position[-1].Profit Output gains and losses are inconsistent with calculated gains and losses

Author: z123zero, Created: 2018-09-03 14:42:14, Updated:

Log('盈亏:', (price - last_price) * lots)  # lots为下单的数量,price为开仓的价格,last_price为平仓的价格
# stocks为平仓操作后的余币,last_stocks为上一次的余币
Log('盈亏(币):', _N(stocks - last_stocks), '盈亏百分比:', _N((stocks - last_stocks) / last_stocks * 100), '%')

The variation of the calculation is the OKEX futures (BTC). The two types of gains and losses, one is the money, the other is the currency, the value is different and the exchange relationship is understandable, but almost every time the symbol is the opposite, the money has always been negative (high buy low sell or low sell high buy), but the currency has always been growing. Why is that?img


More

z123zeroGona can't explain why every time the price of a flat stock is negative, the currency in the account is always growing, right? If you buy at a high price and sell at a low price, you will definitely lose, and if you add the maintenance fee, you will lose even more, why is the balance in the account increasing?

The Little DreamThere are two points to note: 1. GetAccount obtains account information after the trade is opened, minus collateral and real-time floating profit and loss. 2, the fee factor.

The Little DreamThe price of the order and the transaction price. For example, if the current price is 100, I can buy 120 less, but that doesn't mean that the transaction price I bought is 120. In addition, how do you calculate your earnings? Is it the number of coins in the account?