add trade log

This commit is contained in:
Lorenc Pekaj 2018-10-31 20:05:47 +11:00
parent 7645f3f8e8
commit 90cdbd9816

View File

@ -275,6 +275,8 @@ thread StockMarket_OnPurchaseOrder( playerid, stockid, Float: shares )
new Float: sold_shares = amount_remaining > sell_order_shares ? sell_order_shares : amount_remaining; new Float: sold_shares = amount_remaining > sell_order_shares ? sell_order_shares : amount_remaining;
StockMarket_CreateTradeLog( stockid, GetPlayerAccountID( playerid ), sell_order_user_id, sold_shares, ask_price );
new Float: sold_amount_fee = sold_shares * ask_price * STOCK_MARKET_TRADING_FEE; new Float: sold_amount_fee = sold_shares * ask_price * STOCK_MARKET_TRADING_FEE;
UpdateServerVariableFloat( "stock_trading_fees", GetServerVariableFloat( "stock_trading_fees" ) + ( sold_amount_fee / 1000.0 ) ); UpdateServerVariableFloat( "stock_trading_fees", GetServerVariableFloat( "stock_trading_fees" ) + ( sold_amount_fee / 1000.0 ) );
@ -545,7 +547,7 @@ CMD:shares( playerid, params[ ] )
} }
/* ** Functions ** */ /* ** Functions ** */
stock CreateStockMarket( stockid, const name[ 64 ], const symbol[ 4 ], Float: ipo_shares, Float: ipo_price, Float: max_price ) static stock CreateStockMarket( stockid, const name[ 64 ], const symbol[ 4 ], Float: ipo_shares, Float: ipo_price, Float: max_price )
{ {
if ( ! Iter_Contains( stockmarkets, stockid ) ) if ( ! Iter_Contains( stockmarkets, stockid ) )
{ {
@ -591,7 +593,7 @@ stock StockMarket_UpdateEarnings( stockid, amount )
return 1; return 1;
} }
stock StockMarket_GiveShares( stockid, accountid, Float: shares ) static stock StockMarket_GiveShares( stockid, accountid, Float: shares )
{ {
mysql_format( mysql_format(
dbHandle, szBigString, sizeof ( szBigString ), dbHandle, szBigString, sizeof ( szBigString ),
@ -601,7 +603,7 @@ stock StockMarket_GiveShares( stockid, accountid, Float: shares )
mysql_single_query( szBigString ); mysql_single_query( szBigString );
} }
stock StockMarket_UpdateSellOrder( stockid, accountid, Float: shares ) static stock StockMarket_UpdateSellOrder( stockid, accountid, Float: shares )
{ {
mysql_format( mysql_format(
dbHandle, szBigString, sizeof ( szBigString ), dbHandle, szBigString, sizeof ( szBigString ),
@ -611,6 +613,16 @@ stock StockMarket_UpdateSellOrder( stockid, accountid, Float: shares )
mysql_single_query( szBigString ); mysql_single_query( szBigString );
} }
static stock StockMarket_CreateTradeLog( stockid, buyer_acc, seller_acc, Float: shares, Float: price )
{
mysql_format(
dbHandle, szBigString, sizeof ( szBigString ),
"INSERT INTO `STOCK_TRADE_LOG` (`STOCK_ID`, `BUYER_ID`, `SELLER_ID`, `SHARES`, `PRICE`) VALUES (%d, %d, %d, %f, %f)",
stockid, buyer_acc, seller_acc, shares, price
);
mysql_single_query( szBigString );
}
static stock StockMarket_ShowBuySlip( playerid, stockid ) static stock StockMarket_ShowBuySlip( playerid, stockid )
{ {
mysql_tquery( dbHandle, sprintf( "SELECT SUM(`SHARES`) AS `SALE_SHARES` FROM `STOCK_SELL_ORDERS` WHERE `STOCK_ID`=%d", stockid ), "StockMarket_OnShowBuySlip", "dd", playerid, stockid ); mysql_tquery( dbHandle, sprintf( "SELECT SUM(`SHARES`) AS `SALE_SHARES` FROM `STOCK_SELL_ORDERS` WHERE `STOCK_ID`=%d", stockid ), "StockMarket_OnShowBuySlip", "dd", playerid, stockid );
@ -656,4 +668,15 @@ static stock StockMarket_ShowSellSlip( playerid, stockid )
`LIST_DATE` TIMESTAMP default CURRENT_TIMESTAMP, `LIST_DATE` TIMESTAMP default CURRENT_TIMESTAMP,
PRIMARY KEY (STOCK_ID, USER_ID) PRIMARY KEY (STOCK_ID, USER_ID)
); );
DROP TABLE `STOCK_TRADE_LOG`;
CREATE TABLE IF NOT EXISTS `STOCK_TRADE_LOG` (
`ID` int(11) primary key auto_increment,
`STOCK_ID` int(11),
`BUYER_ID` int(11),
`SELLER_ID` int(11),
`SHARES` float,
`PRICE` float,
`LIST_DATE` TIMESTAMP default CURRENT_TIMESTAMP
);
*/ */