Skip to content

New Components - oanda #16542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions components/oanda/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import oanda from "../../oanda.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "oanda-create-order",
name: "Create Order",
description: "Create a new trading order. [See the documentation](https://developer.oanda.com/rest-live-v20/order-ep/)",
version: "0.0.1",
type: "action",
props: {
oanda,
isDemo: {
propDefinition: [
oanda,
"isDemo",
],
},
accountId: {
propDefinition: [
oanda,
"accountId",
(c) => ({
isDemo: c.isDemo,
}),
],
},
type: {
type: "string",
label: "Type",
description: "The type of the order to create",
options: constants.ORDER_TYPES,
reloadProps: true,
},
tradeID: {
propDefinition: [
oanda,
"tradeId",
(c) => ({
isDemo: c.isDemo,
accountId: c.accountId,
}),
],
optional: true,
hidden: true,
},
instrument: {
propDefinition: [
oanda,
"instrument",
],
description: "The instrument for the order. E.g. `AUD_USD`",
optional: true,
hidden: true,
},
units: {
type: "integer",
label: "Units",
description: "The quantity requested to be filled by the Order. A positive number of units results in a long Order, and a negative number of units results in a short Order.",
optional: true,
hidden: true,
},
price: {
type: "string",
label: "Price",
description: "The price threshold specified for the Limit Order. The Order will only be filled by a market price that is equal to or better than this price.",
optional: true,
hidden: true,
},
distance: {
type: "string",
label: "Distance",
description: "Specifies the distance (in price units) from the Account’s current price to use as the Stop Loss Order price. If the Trade is short the Instrument’s bid price is used, and for long Trades the ask is used",
optional: true,
hidden: true,
},
timeInForce: {
type: "string",
label: "Time in Force",
description: "The time-in-force requested for the Order. Restricted to FOK or IOC for a MarketOrder.",
options: constants.TIME_IN_FORCE_OPTIONS,
optional: true,
hidden: true,
},
gtdTime: {
type: "string",
label: "GTD Time",
description: "The date/time when the Stop Order will be cancelled if its timeInForce is \"GTD\".",
optional: true,
hidden: true,
},
priceBound: {
type: "string",
label: "Price Bound",
description: "The worst price that the client is willing to have the Order filled at",
optional: true,
hidden: true,
},
positionFill: {
type: "string",
label: "Position Fill",
description: "Specification of how Positions in the Account are modified when the Order is filled",
options: constants.POSITION_FILL_OPTIONS,
optional: true,
hidden: true,
},
triggerCondition: {
type: "string",
label: "Trigger Condition",
description: "Specification of which price component should be used when determining if an Order should be triggered and filled",
options: constants.ORDER_TRIGGER_CONDITIONS,
optional: true,
hidden: true,
},
},
additionalProps(props) {
if (!this.type) {
return {};
}
const fields = constants.REQUIRED_FIELDS_FOR_ORDER_TYPES[this.type];
for (const [
key,
value,
] of Object.entries(fields)) {
props[key].hidden = false;
props[key].optional = !value;
}
return {};
},
async run({ $ }) {
const {
oanda,
isDemo,
accountId,
type,
...fields
} = this;

const response = await oanda.createOrder({
$,
isDemo,
accountId,
data: {
order: {
type,
...fields,
},
},
});
$.export("$summary", "Successfully created order");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import oanda from "../../oanda.app.mjs";
import constants from "../../common/constants.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "oanda-get-historical-prices",
name: "Get Historical Prices",
description: "Retrieve historical price data for a specified currency pair or instrument within a given time range. [See the documentation](https://developer.oanda.com/rest-live-v20/pricing-ep/)",
version: "0.0.1",
type: "action",
props: {
oanda,
isDemo: {
propDefinition: [
oanda,
"isDemo",
],
},
accountId: {
propDefinition: [
oanda,
"accountId",
(c) => ({
isDemo: c.isDemo,
}),
],
},
instrument: {
propDefinition: [
oanda,
"instrument",
],
},
startTime: {
type: "string",
label: "Start Time",
description: "The start time for historical price data (ISO 8601 format). E.g. `2025-04-01T04:00:00.000000000Z`",
},
endTime: {
type: "string",
label: "End Time",
description: "The end time for historical price data (ISO 8601 format). E.g. `2025-04-01T04:00:00.000000000Z`",
},
price: {
type: "string",
label: "Price",
description: "The Price component(s) to get candlestick data for. Can contain any combination of the characters “M” (midpoint candles) “B” (bid candles) and “A” (ask candles).",
optional: true,
},
granularity: {
type: "string",
label: "Granularity",
description: "The granularity of the candlesticks to fetch",
options: constants.CANDLE_GRANULARITIES,
optional: true,
},
smooth: {
type: "boolean",
label: "Smooth",
description: "A flag that controls whether the candlestick is “smoothed” or not. A smoothed candlestick uses the previous candle’s close price as its open price, while an unsmoothed candlestick uses the first price from its time range as its open price.",
optional: true,
},
includeFirst: {
type: "boolean",
label: "Include First",
description: "A flag that controls whether the candlestick that is covered by the from time should be included in the results. This flag enables clients to use the timestamp of the last completed candlestick received to poll for future candlesticks but avoid receiving the previous candlestick repeatedly.",
optional: true,
},
dailyAlignment: {
type: "integer",
label: "Daily Alignment",
description: "The hour of the day (in the specified timezone) to use for granularities that have daily alignments. minimum=0, maximum=23",
optional: true,
},
alignmentTimezone: {
type: "string",
label: "Alignment Timezone",
description: "The timezone to use for the dailyAlignment parameter. Candlesticks with daily alignment will be aligned to the dailyAlignment hour within the alignmentTimezone. Note that the returned times will still be represented in UTC. [default=America/New_York]",
optional: true,
},
weeklyAlignment: {
type: "string",
label: "Weekly Alignment",
description: "The day of the week used for granularities that have weekly alignment. [default=Friday]",
options: constants.WEEKLY_ALIGNMENT_DAYS,
optional: true,
},
units: {
type: "integer",
label: "Units",
description: "The number of units used to calculate the volume-weighted average bid and ask prices in the returned candles. [default=1]",
optional: true,
},
},
async run({ $ }) {
try {
const response = await this.oanda.getHistoricalPrices({
$,
isDemo: this.isDemo,
accountId: this.accountId,
instrument: this.instrument,
params: {
price: this.price,
granularity: this.granularity,
from: this.startTime,
to: this.endTime,
smooth: this.smooth,
includeFirst: this.includeFirst,
dailyAlignment: this.dailyAlignment,
alignmentTimezone: this.alignmentTimezone,
weeklyAlignment: this.weeklyAlignment,
units: this.units,
},
});
$.export("$summary", `Successfully retrieved ${response.candles.length} trade${response.candles.length === 1
? ""
: "s"}`);
return response;
} catch (error) {
if (error?.message.includes("Maximum value for 'count' exceeded")) {
throw new ConfigurationError("Maximum results exceeded. Update the time range or granularity to return fewer results.");
} else {
console.error("Error retrieving historical prices:", error);
throw error;
}
}
},
};
71 changes: 71 additions & 0 deletions components/oanda/actions/list-trades/list-trades.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import oanda from "../../oanda.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "oanda-list-trades",
name: "List Trades",
description: "Retrieve a list of trades for an account. [See the documentation](https://developer.oanda.com/rest-live-v20/trade-ep/)",
version: "0.0.1",
type: "action",
props: {
oanda,
isDemo: {
propDefinition: [
oanda,
"isDemo",
],
},
accountId: {
propDefinition: [
oanda,
"accountId",
(c) => ({
isDemo: c.isDemo,
}),
],
},
state: {
type: "string",
label: "State",
description: "Filter trades by state",
options: constants.TRADE_STATES,
optional: true,
},
instrument: {
propDefinition: [
oanda,
"instrument",
],
optional: true,
},
count: {
type: "integer",
label: "Count",
description: "The maximum number of Trades to return. [default=50, maximum=500]",
optional: true,
},
beforeId: {
type: "string",
label: "Before ID",
description: "The maximum Trade ID to return. If not provided the most recent Trades in the Account are returned.",
optional: true,
},
},
async run({ $ }) {
const response = await this.oanda.listTrades({
$,
isDemo: this.isDemo,
accountId: this.accountId,
params: {
state: this.state,
instrument: this.instrument,
count: this.count,
beforeID: this.beforeId,
},
});
$.export("$summary", `Successfully retrieved ${response.trades.length} trade${response.trades.length === 1
? ""
: "s"}`);
return response;
},
};
Loading
Loading