首页 > 解决方案 > 转移所有股票功能的最佳方式

问题描述

我正在尝试让我的转账检查我的交易。

如果买方价格高于销售价格,则以销售价格出售给买方。

我需要做什么才能相应地出售它?

如果卖家:

{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。

标签: javascriptmongodb

解决方案


推荐阅读