@agnocon/piece-binance 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.MIT-AP ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) Activepieces AB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ Derived helpers in this folder are adapted from Activepieces (MIT) for use
24
+ inside CX without depending on @activepieces/* packages at runtime.
@@ -0,0 +1,2 @@
1
+ export declare const binance: import("@agnocon/pieces-framework").Piece<undefined>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,sDAUlB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.binance = void 0;
4
+ // Vendored from Activepieces packages/pieces/community/binance/src/index.ts (MIT).
5
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
6
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
7
+ const fetch_pair_price_1 = require("./lib/actions/fetch-pair-price");
8
+ exports.binance = (0, pieces_framework_1.createPiece)({
9
+ displayName: 'Binance',
10
+ description: 'Fetch the price of a crypto pair from Binance',
11
+ minimumSupportedRelease: '0.30.0',
12
+ logoUrl: 'https://cdn.activepieces.com/pieces/binance.png',
13
+ categories: [],
14
+ auth: pieces_framework_1.PieceAuth.None(),
15
+ actions: [fetch_pair_price_1.fetchCryptoPairPrice],
16
+ authors: ["kishanprmr", "khaledmashaly", "abuaboud"],
17
+ triggers: [],
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mFAAmF;AACnF,qEAAqE;AACrE,gEAAmE;AACnE,qEAAsE;AAEzD,QAAA,OAAO,GAAG,IAAA,8BAAW,EAAC;IACjC,WAAW,EAAE,SAAS;IACtB,WAAW,EAAE,+CAA+C;IAC5D,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,iDAAiD;IAC1D,UAAU,EAAE,EAAE;IACd,IAAI,EAAE,4BAAS,CAAC,IAAI,EAAE;IACtB,OAAO,EAAE,CAAC,uCAAoB,CAAC;IAC/B,OAAO,EAAE,CAAC,YAAY,EAAC,eAAe,EAAC,UAAU,CAAC;IAClD,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const fetchCryptoPairPrice: import("@agnocon/pieces-framework").IAction<import("@agnocon/pieces-framework").PieceAuthProperty, {
2
+ first_coin: import("@agnocon/pieces-framework").ShortTextProperty<true>;
3
+ second_coin: import("@agnocon/pieces-framework").ShortTextProperty<true>;
4
+ }>;
5
+ //# sourceMappingURL=fetch-pair-price.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-pair-price.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/fetch-pair-price.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB;;;EA0B/B,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchCryptoPairPrice = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/binance/src/lib/actions/fetch-pair-price.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_common_1 = require("@agnocon/pieces-common");
8
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
9
+ exports.fetchCryptoPairPrice = (0, pieces_framework_1.createAction)({
10
+ name: 'fetch_crypto_pair_price',
11
+ displayName: 'Fetch Pair Price',
12
+ description: 'Fetch the current price of a pair (e.g. BTC/USDT)',
13
+ audience: 'both',
14
+ aiMetadata: { description: 'Fetches the current spot price of a trading pair from the public Binance market data API by combining two coin symbols (e.g. first coin BTC + second coin USDT). Use to look up the live exchange rate of one crypto asset against another. No authentication required; the symbol must be a pair that exists on Binance or the request fails. Read-only lookup, idempotent.', idempotent: true },
15
+ props: {
16
+ first_coin: pieces_framework_1.Property.ShortText({
17
+ displayName: 'First Coin Symbol',
18
+ description: "The currency to fetch the price for (e.g. 'BTC' in 'BTC/USDT')",
19
+ required: true,
20
+ }),
21
+ second_coin: pieces_framework_1.Property.ShortText({
22
+ displayName: 'Second Coin Symbol',
23
+ description: "The currency to fetch the price in (e.g. 'USDT' in 'BTC/USDT')",
24
+ required: true,
25
+ }),
26
+ },
27
+ run(context) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ const { first_coin, second_coin } = context.propsValue;
30
+ if (first_coin && second_coin)
31
+ return yield fetchCryptoPairPriceImpl(`${first_coin}${second_coin}`);
32
+ throw Error('Missing parameter(s)');
33
+ });
34
+ },
35
+ });
36
+ function fetchCryptoPairPriceImpl(symbol) {
37
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
+ const formattedSymbol = symbol
39
+ .replace('/', '')
40
+ .replace(' ', '')
41
+ .toUpperCase();
42
+ const url = `https://api.binance.com/api/v3/ticker/price?symbol=${formattedSymbol}`;
43
+ try {
44
+ const response = yield pieces_common_1.httpClient.sendRequest({
45
+ method: pieces_common_1.HttpMethod.GET,
46
+ url,
47
+ });
48
+ const data = yield response.body;
49
+ return Number(data['price']);
50
+ }
51
+ catch (error) {
52
+ console.error(`Error fetching price for symbol ${symbol}:`, error);
53
+ throw error;
54
+ }
55
+ });
56
+ }
57
+ //# sourceMappingURL=fetch-pair-price.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-pair-price.js","sourceRoot":"","sources":["../../../src/lib/actions/fetch-pair-price.ts"],"names":[],"mappings":";;;;AAAA,0GAA0G;AAC1G,qEAAqE;AACrE,0DAAgE;AAChE,gEAAmE;AAEtD,QAAA,oBAAoB,GAAG,IAAA,+BAAY,EAAC;IAC/C,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EAAE,kBAAkB;IAC/B,WAAW,EAAE,mDAAmD;IAChE,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,EAAE,WAAW,EAAE,8WAA8W,EAAE,UAAU,EAAE,IAAI,EAAE;IAC7Z,KAAK,EAAE;QACL,UAAU,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC7B,WAAW,EAAE,mBAAmB;YAChC,WAAW,EACT,gEAAgE;YAClE,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,WAAW,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,oBAAoB;YACjC,WAAW,EACT,gEAAgE;YAClE,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YACvD,IAAI,UAAU,IAAI,WAAW;gBAC3B,OAAO,MAAM,wBAAwB,CAAC,GAAG,UAAU,GAAG,WAAW,EAAE,CAAC,CAAC;YACvE,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACtC,CAAC;KAAA;CACF,CAAC,CAAC;AAEH,SAAe,wBAAwB,CAAC,MAAc;;QACpD,MAAM,eAAe,GAAG,MAAM;aAC3B,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;aAChB,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;aAChB,WAAW,EAAE,CAAC;QAEjB,MAAM,GAAG,GAAG,sDAAsD,eAAe,EAAE,CAAC;QAEpF,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAC;gBAC5C,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,GAAG;aACJ,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;YACjC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,mCAAmC,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC;YACnE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CAAA"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@agnocon/piece-binance",
3
+ "version": "0.4.6",
4
+ "description": "AgnoCon binance connector",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "LICENSE.MIT-AP"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "vendor": "node ../scripts/vendor-ap.mjs piece-binance"
22
+ },
23
+ "dependencies": {
24
+ "@agnocon/core-utils": "0.2.0",
25
+ "@agnocon/piece-types": "0.3.1",
26
+ "@agnocon/pieces-common": "0.12.8",
27
+ "@agnocon/pieces-framework": "0.36.0",
28
+ "tslib": "2.6.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "20.17.6",
32
+ "typescript": "5.5.4"
33
+ },
34
+ "license": "MIT",
35
+ "agnocon": {
36
+ "originVersion": "0.4.6"
37
+ },
38
+ "publishConfig": {
39
+ "access": "restricted",
40
+ "tag": "latest"
41
+ },
42
+ "keywords": [
43
+ "agnocon",
44
+ "connector"
45
+ ]
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { PieceAuth, createPiece } from '@agnocon/pieces-framework';
2
+ import { fetchCryptoPairPrice } from './lib/actions/fetch-pair-price';
3
+
4
+ export const binance = createPiece({
5
+ displayName: 'Binance',
6
+ description: 'Fetch the price of a crypto pair from Binance',
7
+ minimumSupportedRelease: '0.30.0',
8
+ logoUrl: 'https://cdn.activepieces.com/pieces/binance.png',
9
+ categories: [],
10
+ auth: PieceAuth.None(),
11
+ actions: [fetchCryptoPairPrice],
12
+ authors: ["kishanprmr","khaledmashaly","abuaboud"],
13
+ triggers: [],
14
+ });
@@ -0,0 +1,51 @@
1
+ import { httpClient, HttpMethod } from '@agnocon/pieces-common';
2
+ import { createAction, Property } from '@agnocon/pieces-framework';
3
+
4
+ export const fetchCryptoPairPrice = createAction({
5
+ name: 'fetch_crypto_pair_price',
6
+ displayName: 'Fetch Pair Price',
7
+ description: 'Fetch the current price of a pair (e.g. BTC/USDT)',
8
+ audience: 'both',
9
+ aiMetadata: { description: 'Fetches the current spot price of a trading pair from the public Binance market data API by combining two coin symbols (e.g. first coin BTC + second coin USDT). Use to look up the live exchange rate of one crypto asset against another. No authentication required; the symbol must be a pair that exists on Binance or the request fails. Read-only lookup, idempotent.', idempotent: true },
10
+ props: {
11
+ first_coin: Property.ShortText({
12
+ displayName: 'First Coin Symbol',
13
+ description:
14
+ "The currency to fetch the price for (e.g. 'BTC' in 'BTC/USDT')",
15
+ required: true,
16
+ }),
17
+ second_coin: Property.ShortText({
18
+ displayName: 'Second Coin Symbol',
19
+ description:
20
+ "The currency to fetch the price in (e.g. 'USDT' in 'BTC/USDT')",
21
+ required: true,
22
+ }),
23
+ },
24
+ async run(context) {
25
+ const { first_coin, second_coin } = context.propsValue;
26
+ if (first_coin && second_coin)
27
+ return await fetchCryptoPairPriceImpl(`${first_coin}${second_coin}`);
28
+ throw Error('Missing parameter(s)');
29
+ },
30
+ });
31
+
32
+ async function fetchCryptoPairPriceImpl(symbol: string): Promise<number> {
33
+ const formattedSymbol = symbol
34
+ .replace('/', '')
35
+ .replace(' ', '')
36
+ .toUpperCase();
37
+
38
+ const url = `https://api.binance.com/api/v3/ticker/price?symbol=${formattedSymbol}`;
39
+
40
+ try {
41
+ const response = await httpClient.sendRequest({
42
+ method: HttpMethod.GET,
43
+ url,
44
+ });
45
+ const data = await response.body;
46
+ return Number(data['price']);
47
+ } catch (error) {
48
+ console.error(`Error fetching price for symbol ${symbol}:`, error);
49
+ throw error;
50
+ }
51
+ }