javascript - 转移所有股票功能的最佳方式
问题描述
我正在尝试让我的转账检查我的交易。
如果买方价格高于销售价格,则以销售价格出售给买方。
我需要做什么才能相应地出售它?
如果卖家:
{amount:300,price: 2, firmid: 2}
{amount:200,price: 5, firmid: 2},
买家:
{amount: 400, price: 6, firmid: 2},
那么我将以 2 的价格购买所有 300 只股票,以 5 的价格购买 200 只股票中的 100 只,对于所有买家而言,与卖家相比,最好的解决方法是什么?
使用任何firmid 调用 CheckTransfers。
function CheckTransfers(firmid) {
return GetBuyersForStock(firmid).then(function (Buyers) {
return GetSellersForStock(firmid).then(function (Sellers) {
var NumSeller = 0;
Buyers.forEach(BuyersData => {
if (BuyersData.price >= Sellers[NumSeller].price) {
// BUY AT SALEPRICE
var NumStocks = (BuyersData.amount <= Sellers[NumSeller].amount ? BuyersData.amount : Sellers[NumSeller.amount]);
console.log("BUYING " + NumStocks + " for " + Sellers[NumSeller].price);
}
});
});
});
}
function GetSellersForStock(firmid) {
return StockTransferPlatform.find({type: 'seller', firmid: firmid, completed: false, withdraw: false}).then(function (sellers) {
return sellers;
});
}
function GetBuyersForStock(firmid) {
return StockTransferPlatform.find({type: 'buyer', firmid: firmid, completed: false, withdraw: false}).then(function (sellers) {
return sellers;
});
}
What is the point of the price on the "seller"?
销售由卖方决定,如果买方定价较高,他将被重新找到。
这是股票市场的一种模拟转移。根据我的理解,如果 x 以 200 买入,y 以 105 卖出,它将以 105 卖出,x 得到 95。
解决方案
推荐阅读
- selenoid - selenoid 有像 zalenium 这样的仪表板吗?哪个更推荐使用?
- python - 在文本中查找单词
- java - 为什么在连接后选择在 java spark 数据帧中引发异常?
- java - 如何使用准备好的语句和批处理将大型 csv 导入到带有 java 的 mysql 中
- javascript - Laravel - Ajax 调用没有响应
- qt - 在文本区域中的任意位置单击鼠标时弹出 QDateEdit 的日历小部件,而不仅仅是向下箭头,
- python - 使用 python 或 R 检查相似的名称
- java - 如何添加 Flyway 依赖并构建原生镜像 Quarkus java.lang.ClassNotFoundException: org.jboss.vfs.VirtualFileFilter
- python - 如何优化我的代码?(python-opencv-numpy)
- jquery - 在 SharePoint 中使用 jQuery 的 PnP JavaScript 库