转移所有股票功能的最佳方法

时间:2019-04-23 10:36:32

标签: javascript mongodb

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

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

我需要怎么做才能将其全部出售?

如果卖家:

{amount:300,price: 2, firmid: 2}
{amount:200,price: 5, firmid: 2},

买家:

{amount: 400, price: 6, firmid: 2},

然后我将以2的价格购买全部300股股票,以5的价格购买200股股票中的100股 对于所有购买者而言,与购买者相比,其价格是最好的方法?

使用任何公司编号调用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。

0 个答案:

没有答案