From 98c48ba8535f67706354b29a9389fd8f09227219 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 2 Apr 2024 17:56:37 +0100 Subject: [PATCH] feat: bitfinex implementation --- lib/new-admin/config/accounts.js | 4 ++- lib/new-settings-loader.js | 3 +- lib/plugins/common/ccxt.js | 4 ++- lib/plugins/exchange/bitfinex.js | 21 +++++++++++ .../src/pages/Services/schemas/bitfinex.js | 36 +++++++++++++++++++ .../src/pages/Services/schemas/index.js | 4 ++- 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lib/plugins/exchange/bitfinex.js create mode 100644 new-lamassu-admin/src/pages/Services/schemas/bitfinex.js diff --git a/lib/new-admin/config/accounts.js b/lib/new-admin/config/accounts.js index 5626e052..36bcee22 100644 --- a/lib/new-admin/config/accounts.js +++ b/lib/new-admin/config/accounts.js @@ -4,7 +4,7 @@ const _ = require('lodash/fp') const { ALL } = require('../../plugins/common/ccxt') const { BTC, BCH, DASH, ETH, LTC, USDT, ZEC, XMR, LN, TRX, USDT_TRON } = COINS -const { bitpay, coinbase, itbit, bitstamp, kraken, binanceus, cex, binance } = ALL +const { bitpay, coinbase, itbit, bitstamp, kraken, binanceus, cex, binance, bitfinex } = ALL const TICKER = 'ticker' const WALLET = 'wallet' @@ -17,6 +17,8 @@ const ZERO_CONF = 'zeroConf' const WALLET_SCORING = 'wallet_scoring' const ALL_ACCOUNTS = [ + { code: 'bitfinex', display: 'Bitfinex', class: TICKER, cryptos: bitfinex.CRYPTO }, + { code: 'bitfinex', display: 'Bitfinex', class: EXCHANGE, cryptos: bitfinex.CRYPTO }, { code: 'binance', display: 'Binance', class: TICKER, cryptos: binance.CRYPTO }, { code: 'binanceus', display: 'Binance.us', class: TICKER, cryptos: binanceus.CRYPTO }, { code: 'cex', display: 'CEX.IO', class: TICKER, cryptos: cex.CRYPTO }, diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 670ebc99..40880527 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -27,7 +27,8 @@ const SECRET_FIELDS = [ 'telnyx.apiKey', 'vonage.apiSecret', 'galoy.walletId', - 'galoy.apiSecret' + 'galoy.apiSecret', + 'bitfinex.secret' ] /* diff --git a/lib/plugins/common/ccxt.js b/lib/plugins/common/ccxt.js index 80df027f..db98b460 100644 --- a/lib/plugins/common/ccxt.js +++ b/lib/plugins/common/ccxt.js @@ -9,6 +9,7 @@ const binanceus = require('../exchange/binanceus') const cex = require('../exchange/cex') const bitpay = require('../ticker/bitpay') const binance = require('../exchange/binance') +const bitfinex = require('../exchange/bitfinex') const logger = require('../../logger') const { BTC, BCH, DASH, ETH, LTC, ZEC, USDT, TRX, USDT_TRON, LN } = COINS @@ -24,7 +25,8 @@ const ALL = { CRYPTO: [BTC, ETH, LTC, DASH, ZEC, BCH, USDT, USDT_TRON, TRX, LN], FIAT: 'ALL_CURRENCIES' }, - binance: binance + binance: binance, + bitfinex: bitfinex } function buildMarket (fiatCode, cryptoCode, serviceName) { diff --git a/lib/plugins/exchange/bitfinex.js b/lib/plugins/exchange/bitfinex.js new file mode 100644 index 00000000..4feccb0c --- /dev/null +++ b/lib/plugins/exchange/bitfinex.js @@ -0,0 +1,21 @@ +const { COINS } = require('@lamassu/coins') +const _ = require('lodash/fp') + +const { ORDER_TYPES } = require('./consts') + +const ORDER_TYPE = ORDER_TYPES.MARKET +const { BTC, ETH, LTC, BCH, USDT, LN } = COINS +const CRYPTO = [BTC, ETH, LTC, BCH, USDT, LN] +const FIAT = ['USD', 'EUR'] +const AMOUNT_PRECISION = 8 +const REQUIRED_CONFIG_FIELDS = ['key', 'secret'] + +const loadConfig = (account) => { + const mapper = { + 'key': 'apiKey', + } + const mapped = _.mapKeys(key => mapper[key] ? mapper[key] : key)(account) + return { ...mapped, timeout: 3000 } +} + +module.exports = { loadConfig, REQUIRED_CONFIG_FIELDS, CRYPTO, FIAT, ORDER_TYPE, AMOUNT_PRECISION } diff --git a/new-lamassu-admin/src/pages/Services/schemas/bitfinex.js b/new-lamassu-admin/src/pages/Services/schemas/bitfinex.js new file mode 100644 index 00000000..0609807a --- /dev/null +++ b/new-lamassu-admin/src/pages/Services/schemas/bitfinex.js @@ -0,0 +1,36 @@ +import * as Yup from 'yup' + +import SecretInputFormik from 'src/components/inputs/formik/SecretInput' +import TextInputFormik from 'src/components/inputs/formik/TextInput' + +import { secretTest } from './helper' + +export default { + code: 'bitfinex', + name: 'Bitfinex', + title: 'Bitfinex (Exchange)', + elements: [ + { + code: 'key', + display: 'API Key', + component: TextInputFormik, + face: true, + long: true + }, + { + code: 'secret', + display: 'API Secret', + component: SecretInputFormik + } + ], + getValidationSchema: account => { + return Yup.object().shape({ + key: Yup.string('The API key must be a string') + .max(100, 'The API key is too long') + .required('The API key is required'), + secret: Yup.string('The API secret must be a string') + .max(100, 'The API secret is too long') + .test(secretTest(account?.secret, 'API secret')) + }) + } +} diff --git a/new-lamassu-admin/src/pages/Services/schemas/index.js b/new-lamassu-admin/src/pages/Services/schemas/index.js index 050ccdd2..e077222a 100644 --- a/new-lamassu-admin/src/pages/Services/schemas/index.js +++ b/new-lamassu-admin/src/pages/Services/schemas/index.js @@ -1,5 +1,6 @@ import binance from './binance' import binanceus from './binanceus' +import bitfinex from './bitfinex' import bitgo from './bitgo' import bitstamp from './bitstamp' import blockcypher from './blockcypher' @@ -31,5 +32,6 @@ export default { [cex.code]: cex, [ciphertrace.code]: ciphertrace, [trongrid.code]: trongrid, - [binance.code]: binance + [binance.code]: binance, + [bitfinex.code]: bitfinex }