Skip to content

2284- add binance component #2380

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 3 commits into from
Apr 13, 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
72 changes: 72 additions & 0 deletions docs/src/content/docs/reference/components/binance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "Binance"
description: "Binance is an online exchange where users can trade cryptocurrencies."
---

Binance is an online exchange where users can trade cryptocurrencies.


Categories: Payment Processing


Type: binance/v1

<hr />




## Actions


### Fetch Pair Price
Name: fetchPairPrice

Fetch the price of a crypto pair from Binance.

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| symbol | Symbol | STRING | The symbol of the crypto pair. | true |

#### Example JSON Structure
```json
{
"label" : "Fetch Pair Price",
"name" : "fetchPairPrice",
"parameters" : {
"symbol" : ""
},
"type" : "binance/v1/fetchPairPrice"
}
```

#### Output



Type: OBJECT


#### Properties

| Name | Type | Description |
|:------------:|:------------:|:-------------------:|
| symbol | STRING | The symbol of the crypto pair. |
| price | STRING | The price of the crypto pair. |




#### Output Example
```json
{
"symbol" : "",
"price" : ""
}
```




1 change: 1 addition & 0 deletions server/apps/server-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ dependencies {
implementation(project(":server:libs:modules:components:baserow"))
implementation(project(":server:libs:modules:components:bash"))
implementation(project(":server:libs:modules:components:beamer"))
implementation(project(":server:libs:modules:components:binance"))
implementation(project(":server:libs:modules:components:box"))
implementation(project(":server:libs:modules:components:brevo"))
implementation(project(":server:libs:modules:components:calendly"))
Expand Down
1 change: 1 addition & 0 deletions server/ee/apps/worker-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ dependencies {
implementation(project(":server:libs:modules:components:baserow"))
implementation(project(":server:libs:modules:components:bash"))
implementation(project(":server:libs:modules:components:beamer"))
implementation(project(":server:libs:modules:components:binance"))
implementation(project(":server:libs:modules:components:box"))
implementation(project(":server:libs:modules:components:brevo"))
implementation(project(":server:libs:modules:components:calendly"))
Expand Down
2 changes: 2 additions & 0 deletions server/libs/modules/components/binance/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version="1.0"

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.binance;

import static com.bytechef.component.definition.ComponentDsl.component;

import com.bytechef.component.ComponentHandler;
import com.bytechef.component.binance.action.BinanceFetchPairPriceAction;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.google.auto.service.AutoService;

/**
* @author Marija Horvat
*/
@AutoService(ComponentHandler.class)
public class BinanceComponentHandler implements ComponentHandler {

private static final ComponentDefinition COMPONENT_DEFINITION = component("binance")
.title("Binance")
.description("Binance is an online exchange where users can trade cryptocurrencies.")
.icon("path:assets/binance.svg")
.categories(ComponentCategory.PAYMENT_PROCESSING)
.actions(BinanceFetchPairPriceAction.ACTION_DEFINITION);

@Override
public ComponentDefinition getDefinition() {
return COMPONENT_DEFINITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.binance.action;

import static com.bytechef.component.binance.constant.BinanceConstants.SYMBOL;
import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.object;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.responseType;

import com.bytechef.component.binance.util.BinanceUtils;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http;
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TypeReference;

/**
* @author Marija Horvat
*/
public class BinanceFetchPairPriceAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("fetchPairPrice")
.title("Fetch Pair Price")
.description("Fetch the price of a crypto pair from Binance.")
.properties(
string(SYMBOL)
.label("Symbol")
.description("The symbol of the crypto pair.")
.options((ActionOptionsFunction<String>) BinanceUtils::getSymbolsOptions)
.required(true))
.output(
outputSchema(
object()
.properties(
string(SYMBOL)
.description("The symbol of the crypto pair."),
string("price")
.description("The price of the crypto pair."))))
.perform(BinanceFetchPairPriceAction::perform);

private BinanceFetchPairPriceAction() {
}

public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
return context.http(http -> http.get("https://api.binance.com/api/v3/ticker/price"))
.queryParameter(SYMBOL, inputParameters.getRequiredString(SYMBOL))
.configuration(responseType(Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.binance.constant;

/**
* @author Marija Horvat
*/
public class BinanceConstants {

public static final String SYMBOL = "symbol";

private BinanceConstants() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.binance.util;

import static com.bytechef.component.binance.constant.BinanceConstants.SYMBOL;
import static com.bytechef.component.definition.ComponentDsl.option;
import static com.bytechef.component.definition.Context.Http.responseType;

import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http;
import com.bytechef.component.definition.Option;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TypeReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author Marija Horvat
*/
public class BinanceUtils {

private BinanceUtils() {
}

public static List<Option<String>> getSymbolsOptions(
Parameters inputParameters, Parameters connectionParameters, Map<String, String> dependencyPaths,
String searchText, Context context) {

Map<String, Object> body = context.http(http -> http.get("https://api.binance.com/api/v3/exchangeInfo"))
.configuration(responseType(Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});

List<Option<String>> options = new ArrayList<>();

if (body.get("symbols") instanceof List<?> symbols) {
for (Object object : symbols) {
if (object instanceof Map<?, ?> map) {
String symbol = (String) map.get(SYMBOL);

options.add(option(symbol, symbol));
}
}
}

return options;
}
}
Loading
Loading