KO-9 / node-trading212

NodeJS Trading212 Unofficial API
19 stars 3 forks source link

Add support for buckets and fix demo/live #11

Closed vk496 closed 1 year ago

vk496 commented 1 year ago

Hello,

Thank you for this project! I'm glad that at least someone decided to use API and not as a full web motor.

I fixed the live/demo modes, implemented functions to get buckets info and emit a bucket fund. Also, reduced the constructor and did beautify with VScode.

A working example to fund a bucket:

const trading212Handler = require('trading212');

const LIVE_SESSION = "12341234-abcd-abcd-56785678";
const DEMO_SESSION = "12341234-abcd-abcd-56785678";

//Create handle and client
const trading212 = new trading212Handler('demo', DEMO_SESSION);

async function run() {
  return new Promise((resolve, reject) =>
    trading212
      .on('platform-subscribed', async () => {
        // trading212.getBuckets();
        let bucketID = await trading212.getBucketId("My xd AAA");

        trading212.fundBucket(bucketID, 15, "BY_TARGETS");

      })
      .on('bucket-funded', (output) => {
        console.log('Funded!:', output)
        resolve(output)
      })
  )
}

(async () => {
  await run();
  console.log("Bye Bye")
  // This is were you put your code
})();

Missing stuff (in my opinion):

Hope it will be usueful :)

KO-9 commented 1 year ago

Sorry it took me a little while to get round to looking at this. Looks good though, thanks for the contributions