How to import an existing app on pipedream into node.js

Hello, I’m trying to get bybit app into the node, so I can modify the parameters (API url to be exact)
Could anyone be so kind to help me out - I need to import ByBit APP into code, but it doesn’t want to.
The original line (on github) is:

import bybit from "../../bybit.app.mjs";

i’m trying to use

import bybit from "pipedream/components/bybit/actions/generic-api-call/bybit.app.mjs"
export default defineComponent({
  props: {
    bybit: {
      type: "app",
      app: "bybit",
    },
    symbol: {
      propDefinition: [
        bybit,
        "symbol",
      ],

it says

"Code Error

could not compute configurable props"

and the original script location:

Could you help with advice, whether I can import bybit app somehow and modify this code (only the api URL), so I can create a workflow with it?

Thank you!

Hello @femaste,

I afraid this is not a valid approach as you could not change the action code directly. To use a different API url, you might need to replicate (copy & paste) the code from bybits actions generic-api-call

1 Like

That’s also not possible, unless I use the github source, and then it requires to import the bybit app or define it, but the code doesn’t compile, or sends into testing forever.
I can just create a generic api call, but why can’t I use the existing order create app, it’s basically the same in my case, as I’m trying to send the exactly the same command, but for copytrading url.
Same problem…

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    bybit: {
      type: "app",
      app: "bybit",
    }
  },
  async run({steps, $}) {
    return await axios($, {
      url: `https://api.bybit.com/v2/public/time`,
    })
  },
})

should be combined somehow with

import bybit from "../../bybit.app.mjs";

export default {
  name: "ByBit Generic API Call",
  version: "0.0.1",
  key: "bybit-generic-api-call",
  description: "Make any API call as per the documentation." +
      "[reference](https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-introduction)",
  props: {
    bybit,
    http_method: {
      label: "HTTP Method",
      description: "HTTP Method as per API documentation",
      type: "string",
      optional: false,
      options: [
        "GET",
        "POST",
      ],
    },

@femaste I think this part is already quite correct, as it uses bybit authentication.

You then can use the auth data to use any bybit API without using existing action.

Additionally, to import the bybits app from Pipedream, you can use

import bybit from '@pipedream/bybit'

instead of

import bybit from "../../bybit.app.mjs";

Thank you, now the import worked, but partially,

Code Error
Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘crypto-js’ imported from /tmp/tmp-8anTqHgyfVytc/987e1f4be77b1936a26382752f4224144e92b18ab6bd09ee1ad12ed538e01a93/node_modules/@pipedream/bybit/bybit.app.mjs

The bybit.app.mjs has it, but no idea why it can’t be located.
import CryptoJS from "crypto-js";

Even I solved the import of crypto.js, but now seems every module can’t be found from bybit.app

Code Error

Error [ERR_MODULE_NOT_FOUND]: Cannot find module ‘/tmp/tmp-86dY004ixUvaK/c9832e6e7f54ba27103f89c224b70be684d0d33e412389ad3f4d77f5d96e3330/node_modules/@pipedream/bybit/common/constants.mjs’ imported from /tmp/tmp-86dY004ixUvaK/c9832e6e7f54ba27103f89c224b70be684d0d33e412389ad3f4d77f5d96e3330/node_modules/@pipedream/bybit/bybit.app.mjs

@femaste, if this is the case then I would suggest to use Bybit app auth on your Node.js code and call any Bybit API using it, for example as you stated above

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    bybit: {
      type: "app",
      app: "bybit",
    }
  },
  async run({steps, $}) {
    return await axios($, {
      url: `https://api.bybit.com/v2/public/time`,
    })
  },
})

Additionally you can add new props, for example:

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    bybit: {
      type: "app",
      app: "bybit",
    },
    http_method: {
      label: "HTTP Method",
      description: "HTTP Method as per API documentation",
      type: "string",
      optional: false,
      options: [
        "GET",
        "POST",
      ],
    },
  },
  async run({steps, $}) {
    return await axios($, { 
      // use the prop
      method: this.http_method,
      url: `https://api.bybit.com/v2/public/time`,
    })
  },
})

I would NOT recommend spending time working around what is not documented on Pipedream official component doc. You can spend time reading through the whole Pipedream component doc to see what it is capable of

1 Like

Thank you for help, I’ve managed to get this code finally. But the testing does not go through and I can’t save the workflow (for some reason it freezes while saving or testing it)
I’ll try my best with this.

Here’s the final code as I managed to handle it:

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    bybit: {
      type: "app",
      app: "bybit",
    },
    API_PATH: {
      label: "API PATH",
      description: "HTTP Method as per API documentation",
      type: "string",
      optional: false,
      options: [
        "https://api.bybit.com/v2/private/linear/order/create",
        "https://api.bybit.com/v2/public/time",
      ],
    },
    API_METHOD: {
      label: "HTTP Method",
      description: "HTTP Method as per API documentation",
      type: "string",
      optional: false,
      options: [
        "GET",
        "POST",
      ],
    },
    symbol: {
      label: "symbol",
      description: "HTTP Method as per API documentation",
      type: "string",
      optional: false,
    },
    side: {
      label: "side",
      description: "parameter",
      type: "string",
      optional: false,
    },
    order_type: {
      label: "order_type",
      description: "parameter",
      type: "string",
      optional: false,
    },
    qty: {
      label: "quanity",
      description: "parameter",
      type: "string",
      optional: false,
    },
    price: {
      label: "price",
      description: "parameter",
      type: "string",
      optional: false,
    },
    time_in_force: {
      label: "time_in_force",
      description: "parameter",
      type: "string",
      optional: false,
    },
    reduce_only: {
      label: "reduce_only",
      description: "parameter",
      type: "string",
      optional: false,
    },
    close_on_trigger: {
      label: "close_on_trigger",
      description: "parameter",
      type: "string",
      optional: false,
    },
    order_link_id: {
      label: "order_link_id",
      description: "parameter",
      type: "string",
      optional: false,
    },
    take_profit: {
      label: "take_profit",
      description: "parameter",
      type: "string",
      optional: false,
    },
    stop_loss:{
      label: "stop_loss",
      description: "parameter",
      type: "string",
      optional: false,
    },
    tp_trigger_by:{
      label: "tp_trigger_by",
      description: "parameter",
      type: "string",
      optional: false,
    },
    sl_trigger_by: {
      label: "sl_trigger_by",
      description: "parameter",
      type: "string",
      optional: false,
    },
    position_idx: {
      label: "position_idx",
      description: "parameter",
      type: "string",
      optional: false,
    },
      },
 async run({ $ }) {
    const returnValue = await this.bybit.makeRequest(API_METHOD, API_PATH, this);
    if (returnValue.ret_code) {
      throw new Error(returnValue.ret_msg);
    } else {
      $.export("$summary", "Active Order Placed Successfully");
    }
    return returnValue;
  },
})  

it doesn’t show any errors, nor completes the testing. I suppose something is wrong with the request, will try hard tomorrow! :slight_smile:
Thank you once again for guiding me into a solution!

2 Likes

Last problem that seems to be hard for me to solve:

I have the action as follows, with imported bybit app and vars from pipedream.

 async run({ $ }) {
    const API_METHOD="POST"
    const API_PATH="/private/linear/order/create"
    const returnValue = await this.bybit.makeRequest(API_METHOD, API_PATH, this);
    if (returnValue.ret_code) {
      throw new Error(returnValue.ret_msg);
    } else {
      $.export("$summary", "Active Order Placed Successfully");
    }
    return returnValue;
  },
})  

and it gives this error, what could be the problem and how to solve it?

TypeError

this.bybit.makeRequest is not a function

Details

    at Object.run (file:///tmp/__pdg__/dist/code/89875e3adccc3e39c1e326949588840080fc1774942fe82c185d76d5d10fe25f/component.mjs:107:42)
    at global.executeComponent (/var/task/launch_worker.js:139:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:598:28)

@femaste, if you use bybit as prop, it will not have the function in Pipedream’s bybit component. It will only have auth information

I would strongly suggest to call to bybit API directly using axios in this case, like this: pipedream/bybit.app.mjs at a3012507af7f51a07bdbed16031c69c455395c33 · PipedreamHQ/pipedream · GitHub