javascript - ramda 中的 Concat 对象(项目 nodejs)
问题描述
我正在尝试在我的 nodejs 后端应用 ramda 来连接对象,但是当它们相等时我无法建立对象的关系。
这里我给你看第一种安排:
{
"ETHBTC": "0.03907000",
"LTCBTC": "0.00481700",
"BNBBTC": "0.00901600",
"NEOBTC": "0.00200600",
"QTUMETH": "0.00902000",
"EOSETH": "0.00310500",
"SNTETH": "0.00008902",
"BNTETH": "0.00308500",
"BCCBTC": "0.07908100",
"GASBTC": "0.00032410",
"BNBETH": "0.23078000",
"BTCUSDT": "55974.56000000",
"ETHUSDT": "2186.71000000",
"HSRBTC": "0.00041400",
"OAXETH": "0.00017780",
"DNTETH": "0.00002801",
"MCOETH": "0.00577200"
}
这里我给你看第二种安排:
[
{
"asset": "BTC",
"free": "0.01054959",
"locked": "0.00000000"
},
{
"asset": "LTC",
"free": "0.00000000",
"locked": "0.00000000"
},
{
"asset": "ETH",
"free": "0.00000000",
"locked": "0.00000000"
}
]
这里我给你展示第三种安排:
[
{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT"
],
"icebergAllowed": true,
"ocoAllowed": true,
"quoteOrderQtyMarketAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": true,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
},
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "5",
"multiplierDown": "0.2",
"avgPriceMins": 5
},
{
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00010000",
"applyToMarket": true,
"avgPriceMins": 5
},
{
"filterType": "ICEBERG_PARTS",
"limit": 10
},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "1784.90123628",
"stepSize": "0.00000000"
},
{
"filterType": "MAX_NUM_ORDERS",
"maxNumOrders": 200
},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5
}
],
"permissions": [
"SPOT",
"MARGIN"
]
},
{
"symbol": "LTCBTC",
"status": "TRADING",
"baseAsset": "LTC",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT"
],
"icebergAllowed": true,
"ocoAllowed": true,
"quoteOrderQtyMarketAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": true,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
},
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "5",
"multiplierDown": "0.2",
"avgPriceMins": 5
},
{
"filterType": "LOT_SIZE",
"minQty": "0.01000000",
"maxQty": "100000.00000000",
"stepSize": "0.01000000"
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00010000",
"applyToMarket": true,
"avgPriceMins": 5
},
{
"filterType": "ICEBERG_PARTS",
"limit": 10
},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "10633.87362057",
"stepSize": "0.00000000"
},
{
"filterType": "MAX_NUM_ORDERS",
"maxNumOrders": 200
},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5
}
],
"permissions": [
"SPOT",
"MARGIN"
]
},
{
"symbol": "BNBBTC",
"status": "TRADING",
"baseAsset": "BNB",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT"
],
"icebergAllowed": true,
"ocoAllowed": true,
"quoteOrderQtyMarketAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": true,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000010",
"maxPrice": "100000.00000000",
"tickSize": "0.00000010"
},
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "5",
"multiplierDown": "0.2",
"avgPriceMins": 5
},
{
"filterType": "LOT_SIZE",
"minQty": "0.01000000",
"maxQty": "100000.00000000",
"stepSize": "0.01000000"
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00010000",
"applyToMarket": true,
"avgPriceMins": 5
},
{
"filterType": "ICEBERG_PARTS",
"limit": 10
},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "3604.01847116",
"stepSize": "0.00000000"
},
{
"filterType": "MAX_NUM_ORDERS",
"maxNumOrders": 200
},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5
}
],
"permissions": [
"SPOT",
"MARGIN"
]
},
{
"symbol": "BTCUSDT",
"status": "TRADING",
"baseAsset": "BTC",
"baseAssetPrecision": 8,
"quoteAsset": "USDT",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT"
],
"icebergAllowed": true,
"ocoAllowed": true,
"quoteOrderQtyMarketAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": true,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.01000000",
"maxPrice": "1000000.00000000",
"tickSize": "0.01000000"
},
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "5",
"multiplierDown": "0.2",
"avgPriceMins": 5
},
{
"filterType": "LOT_SIZE",
"minQty": "0.00000100",
"maxQty": "9000.00000000",
"stepSize": "0.00000100"
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "10.00000000",
"applyToMarket": true,
"avgPriceMins": 5
},
{
"filterType": "ICEBERG_PARTS",
"limit": 10
},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "82.65659251",
"stepSize": "0.00000000"
},
{
"filterType": "MAX_NUM_ORDERS",
"maxNumOrders": 200
},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5
}
],
"permissions": [
"SPOT",
"MARGIN"
]
}
]
我要做的是首先从第二个数组中获取资产值,然后在第三个数组中查找它的符号。
一旦我知道它的符号是什么,我就使用这个符号在第三个数组中查找它的信息(资产、空闲、锁定),即符号(第二个数组)=== 资产(第三个数组)。
一旦我有了三个数组中的货币信息,我必须将第一个数组中的数据与第二个数组合并(第一个数组的值必须更改为成本)
在这里,我向您展示了所需的结果:
[
{
"asset": "BTC",
"free": "0.01054959",
"locked": "0.00000000",
"cost": "55974.56000000"
},
{
"asset": "LTC",
"free": "0.00000000",
"locked": "0.00000000",
"cost": "0.00481700"
},
{
"asset": "ETH",
"free": "0.00000000",
"locked": "0.00000000",
"cost": "0.03907000"
}
]
解决方案
使用 Javascript 的解决方案Map
我建议创建一个映射Map
到.zs
baseAsset
symbol
然后使用和数组循环ys
并构造cost
字段。Map
xs
const
xs = {ETHBTC: "0.03907000", LTCBTC: "0.00481700", BNBBTC: "0.00901600", NEOBTC: "0.00200600", QTUMETH: "0.00902000", EOSETH: "0.00310500", SNTETH: "0.00008902", BNTETH: "0.00308500", BCCBTC: "0.07908100", GASBTC: "0.00032410", BNBETH: "0.23078000", BTCUSDT: "55974.56000000", ETHUSDT: "2186.71000000", HSRBTC: "0.00041400", OAXETH: "0.00017780", DNTETH: "0.00002801", MCOETH: "0.00577200"},
ys = [{asset: "BTC", free: "0.01054959", locked: "0.00000000"}, {asset: "LTC", free: "0.00000000", locked: "0.00000000"}, {asset: "ETH", free: "0.00000000", locked: "0.00000000"}],
zs = [{symbol: "ETHBTC", status: "TRADING", baseAsset: "ETH", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000100", maxPrice: "100000.00000000", tickSize: "0.00000100"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.00100000", maxQty: "100000.00000000", stepSize: "0.00100000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "1784.90123628", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "LTCBTC", status: "TRADING", baseAsset: "LTC", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000100", maxPrice: "100000.00000000", tickSize: "0.00000100"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.01000000", maxQty: "100000.00000000", stepSize: "0.01000000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "10633.87362057", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "BNBBTC", status: "TRADING", baseAsset: "BNB", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000010", maxPrice: "100000.00000000", tickSize: "0.00000010"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.01000000", maxQty: "100000.00000000", stepSize: "0.01000000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "3604.01847116", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "BTCUSDT", status: "TRADING", baseAsset: "BTC", baseAssetPrecision: 8, quoteAsset: "USDT", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.01000000", maxPrice: "1000000.00000000", tickSize: "0.01000000"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.00000100", maxQty: "9000.00000000", stepSize: "0.00000100"}, {filterType: "MIN_NOTIONAL", minNotional: "10.00000000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "82.65659251", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}],
zsMap = new Map(zs.map(({baseAsset, symbol}) => [baseAsset, symbol])),
desired = ys.map(o => ({...o, cost: xs[zsMap.get(o.asset)]}))
console.log(desired)
相同的解决方案,但使用 IIFE
const
xs = {ETHBTC: "0.03907000", LTCBTC: "0.00481700", BNBBTC: "0.00901600", NEOBTC: "0.00200600", QTUMETH: "0.00902000", EOSETH: "0.00310500", SNTETH: "0.00008902", BNTETH: "0.00308500", BCCBTC: "0.07908100", GASBTC: "0.00032410", BNBETH: "0.23078000", BTCUSDT: "55974.56000000", ETHUSDT: "2186.71000000", HSRBTC: "0.00041400", OAXETH: "0.00017780", DNTETH: "0.00002801", MCOETH: "0.00577200"},
ys = [{asset: "BTC", free: "0.01054959", locked: "0.00000000"}, {asset: "LTC", free: "0.00000000", locked: "0.00000000"}, {asset: "ETH", free: "0.00000000", locked: "0.00000000"}],
zs = [{symbol: "ETHBTC", status: "TRADING", baseAsset: "ETH", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000100", maxPrice: "100000.00000000", tickSize: "0.00000100"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.00100000", maxQty: "100000.00000000", stepSize: "0.00100000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "1784.90123628", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "LTCBTC", status: "TRADING", baseAsset: "LTC", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000100", maxPrice: "100000.00000000", tickSize: "0.00000100"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.01000000", maxQty: "100000.00000000", stepSize: "0.01000000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "10633.87362057", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "BNBBTC", status: "TRADING", baseAsset: "BNB", baseAssetPrecision: 8, quoteAsset: "BTC", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.00000010", maxPrice: "100000.00000000", tickSize: "0.00000010"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.01000000", maxQty: "100000.00000000", stepSize: "0.01000000"}, {filterType: "MIN_NOTIONAL", minNotional: "0.00010000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "3604.01847116", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}, {symbol: "BTCUSDT", status: "TRADING", baseAsset: "BTC", baseAssetPrecision: 8, quoteAsset: "USDT", quotePrecision: 8, quoteAssetPrecision: 8, baseCommissionPrecision: 8, quoteCommissionPrecision: 8, orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"], icebergAllowed: true, ocoAllowed: true, quoteOrderQtyMarketAllowed: true, isSpotTradingAllowed: true, isMarginTradingAllowed: true, filters: [{filterType: "PRICE_FILTER", minPrice: "0.01000000", maxPrice: "1000000.00000000", tickSize: "0.01000000"}, {filterType: "PERCENT_PRICE", multiplierUp: "5", multiplierDown: "0.2", avgPriceMins: 5}, {filterType: "LOT_SIZE", minQty: "0.00000100", maxQty: "9000.00000000", stepSize: "0.00000100"}, {filterType: "MIN_NOTIONAL", minNotional: "10.00000000", applyToMarket: true, avgPriceMins: 5}, {filterType: "ICEBERG_PARTS", limit: 10}, {filterType: "MARKET_LOT_SIZE", minQty: "0.00000000", maxQty: "82.65659251", stepSize: "0.00000000"}, {filterType: "MAX_NUM_ORDERS", maxNumOrders: 200}, {filterType: "MAX_NUM_ALGO_ORDERS", maxNumAlgoOrders: 5}], permissions: ["SPOT", "MARGIN"]}],
desired = ((zsMap) =>
ys.map(o => ({ ...o, cost: xs[zsMap.get(o.asset)] })))(
new Map(zs.map(({ baseAsset, symbol }) => [baseAsset, symbol]))
);
console.log(desired);
推荐阅读
- amazon-web-services - 如何递归删除对象
- javascript - 过滤功能不会删除我的空行 - Google App Script
- spring-boot - 分离 OAuth2 授权服务器和资源服务器
- asp.net-mvc - 捆绑和缩小的脚本乱序
- python - 数据表 fread 函数中的 index_col 参数
- r - 不包括重复出现值 R 的 sample() 函数
- r - 具有分组的数据表中多行和多列的中位数
- c# - Visual Studio 2017 - ASP.NET 对 .cshtml 的更改未反映
- php - Laravel 5.8 自定义规则 - 返回 False 很慢
- angular - 如何在不重新编译 Angular 应用程序的情况下刷新 JSON 文件?