Disclosure of Invention
The invention aims to provide a P2P energy trading method based on an intelligent contract, which combines a block chain with energy P2P trading, exerts the advantages of the block chain, makes up the problems of the existing energy trading market, promotes the consumption of clean energy, realizes the automatic execution of the P2P energy trading between a producer and a consumer under the intelligent contract, and is beneficial to improving the energy trading efficiency and reducing the cost.
In order to achieve the purpose, the invention provides the following scheme:
a P2P energy trading method based on intelligent contracts comprises the following steps:
s1, aiming at internal transaction of the microgrid, calling an intelligent contract function to register the microgrid with the serial number id, registering users, namely a producer and a consumer under the microgrid, initializing the microgrid and the users at the same time, and constructing a P2P energy transaction model between the producer and the consumer based on an intelligent contract;
s2, performing P2P energy trading between the prosumers and the consumers by adopting a P2P energy trading model between the prosumers and the consumers by adopting a PC-DA (personal computer-data acquisition), and generating a trading order;
s3, automatically clearing the generated trade order under the intelligent contract;
s4, after the matching of the trading orders is completed, calculating feedback values of all the producers and consumers participating in the current round of trading, and performing user feedback analysis;
and S5, after the set time is reached, the node responsible for packaging packs the generated transaction orders into blocks, then the blocks are transmitted in the network, and after the consensus node reaches consensus, the blocks are linked up, so that the round of transaction is completed.
Further, in step S1, for the internal transaction of the microgrid, calling an intelligent contract function to register the microgrid with the serial number id, and registering users, i.e., both a producer and a consumer, under the microgrid, initializing the microgrid and the users at the same time, and constructing a P2P energy transaction model between the producer and the consumer based on the intelligent contract, specifically including:
the selling price and the purchasing price of the micro-grid energy with the serial number id are respectively SP
id 、BP
id (ii) a And setting a microgrid id of m
id Individual person of birth and consumption, n
id The set of consumers and the set of the producers and the consumers
Collection for consumer
Respectively indicating the person of birth and consumption
The selling price and the amount of the energy sold, wherein i is 1, 2.
Respectively represent consumers
The purchase price and the amount of energy purchased, where j is 1, 2.
Further, in step S2, the P2P energy trading model between the producer and the consumer adopts PC-DA to perform P2P energy trading between the producer and the consumer, and generate a trade order, specifically including:
the patients of both birth and consumption
Invoking intelligent contract function publishing
And
then automatically moving contactThe order of the hair is regulated according to
Adding the selling arrays in a sequence from low to high;
at the same time, the consumer
Invoking intelligent contract function publishing
And
and judge the consumers
Whether there are sufficient token purchases of
If there are enough tokens, automatically triggers a sort rule according to
Add purchase array in high to low order, otherwise refuse consumer
Participating in the energy transaction of the current round;
and generating a trade order when the conditions are met according to the one-to-one matching of the selling array and the purchasing array.
Further, the generating a trade order according to one-to-one matching between the selling array and the purchasing array and meeting the condition specifically includes:
judging whether the selling price of the first element of the selling array, the quantity of the selling energy, the purchase price of the first element of the purchasing array and the quantity of the purchasing energy meet the requirements or not, namely whether the selling price, the quantity of the selling energy, the purchase price of the first element of the purchasing array and the purchasing energy quantity meet the requirements simultaneously or not
And
and forming a matched trading order by the two trading parties meeting the requirement, then sequentially iterating until the conditions are not met, and trading the remaining unmatched users with the microgrid operator.
Further, step S3, automatically clearing the generated trade order under the intelligent contract, specifically includes:
s301, taking an intelligent contract standard ERC20 as a basic agreement, converting the token and the energy price by adopting an exchange rate, wherein the average price and the mixed price refer to real world currency, the token needs to be converted before settlement, and the exchange mechanism is shown as a formula (1):
token=token_rate*price (1)
wherein token represents token, token _ rate represents exchange rate, and price represents currency;
s302, setting the average price clearing mechanism time to be 1 hour, and adopting average price clearing when the P2P energy transaction is finished in the mode; when the producer bid and the consumer bid are the same, then the average price equals the producer bid and the consumer bid; when the producer and consumer bid is larger than the consumer bid, a matching order cannot be formed; when the producer and the consumer bid less than the consumer bid, clearing according to the average price of the producer and the consumer; wherein the average price
It is the case of both birth and consumption
Is/are as follows
And consumers
Is/are as follows
The average value of the two is shown in formula (2):
s303, setting the mixed price clearing mechanism time to be 1 hour, adopting the mixed price clearing to clear the P2P energy source transaction in the mode, and leading the producer and the consumer to be on or off
And consumers
Mixed price of transaction
As shown in formula (3):
further, in step S4, after the matching of the trade order is completed, feedback values of all the producers and consumers participating in the current round of trade are calculated, and the user feedback analysis is performed, which specifically includes:
s401, calculating the yield of the producers and the consumers: the patients of both birth and consumption
As a benefit of the producer
As shown in formula (4):
in the formula (I), the compound is shown in the specification,
respectively representing producers and consumers under the id of the microgrid
And consumers
Energy quantity of trading, microgrid operator trading; p is a radical of
ij The person who is born and goes bad
And consumers
The bargain price of (c); describing the relationship between the output energy and the equipment expenditure by adopting an ln function;
s402, calculating consumer income: consumers
Gain of (2)
As shown in formula (5):
in the formula (I), the compound is shown in the specification,
representing consumers
Benefits from purchasing energy;
respectively represent consumers
The benefit factor of (2);
respectively representing consumers under the microgrid id
The syndrome of labor and consumption
Energy quantity of trading, microgrid operator trading; describing the relation between the energy purchase and the benefit of the consumer by adopting a quadratic function and using the quadratic function
Representing consumers
The benefit factor of (1);
s403, calculating a feedback value of the indigestion person: the patients of both birth and consumption
Is fed back to
As shown in formula (6):
in the formula (I), the compound is shown in the specification,
respectively indicating the person of birth and consumption
The price feedback value, the energy transaction quantity feedback value and the income feedback value;
representing a preference coefficient;
s404, calculating a consumer feedback value: consumers
Is fed back to
As shown in formula (7):
in the formula (I), the compound is shown in the specification,
respectively represent consumers
The price feedback value, the energy transaction quantity feedback value and the income feedback value;
the preference coefficient is represented.
According to the specific embodiment provided by the invention, the invention discloses the following technical effects: the intelligent contract based on the intelligent contract P2P energy transaction method provided by the invention takes the intelligent contract of the block chain as an important component part of the P2P energy transaction, plays an important role in the transaction between a producer and a consumer, and brings a series of advantages to the P2P energy transaction:
1) the traditional trading mode of the power grid needs a completely trusted third party intermediary as a trading center, and the invention adopts a block chain and intelligent contract mode to ensure that nodes added into the block chain can unconditionally trust each other, thereby achieving the aim of decentralization;
2) the P2P energy transaction between the producer and consumer can not only locally consume renewable energy and reduce the loss in the transmission process, but also has larger profit for the producer and consumer in the P2P energy transaction compared with the traditional energy transaction mode;
3) the P2P energy trading model is deployed on the intelligent contract, users with demand trading can register and join in energy trading and issue own demands, and the users only need to wait for the intelligent contract to match the contract without human intervention, so that a large amount of manpower, material resources and financial resources are saved;
4) the automatic clearing function saves a great deal of time, and two transaction parties do not need to worry about the condition that energy is not used or the condition that energy cannot be used after payment;
5) user feedback values are set in the intelligent contract to measure the satisfaction degree of the user to the transaction, so that a microgrid operator can well master the energy transaction condition of the user;
6) the trade orders are finally stored on the blockchain, the property of the blockchain enables the trade information not to be falsified, and all users can conveniently and timely trace back the trade orders.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The block chain is used as a novel distributed account book, has the characteristics of openness, transparency, decentralization, no tampering, traceability and the like, and is beneficial to improving the energy transaction efficiency, reducing the cost and the like. At present, a point-to-point energy trading mode, called P2P (peer-to-peer) energy trading for short, is adopted in an energy trading market, and a block chain and energy P2P trading are combined, so that the advantages of the block chain can be exerted, the problems in the energy trading market are solved, the consumption of clean energy is promoted, and the P2P energy trading between a producer and a consumer is automatically executed under an intelligent contract. Therefore, the object of the present invention is to develop research on energy trading between a producer and a consumer in the context of a microgrid and to attempt to propose a P2P energy trading method based on a smart contract with the aid of a blockchain smart contract.
In a blockchain, an intelligent contract is a set of code that is deployed on the blockchain and is capable of running according to predefined logic rules. At present, the application platforms of intelligent contracts mainly include etherhouses (Ethereum) and hyper ledgers (hyper Legendre Fabric). The Ethenhouse is used as a platform for using the intelligent contract at the earliest time, the development is mature, the intelligent contract is compiled by adopting the solidity language, and the Ethenhouse virtual machine EVM is used as the operating environment of the intelligent contract and can isolate the outside, so that the intelligent contract can be operated well. The intelligent contract in the super ledger is also called as 'chain code', the chain code is mainly compiled by adopting languages such as go, java and node.
The micro-grid is used as a regional power grid and provides a supporting condition for the consumption of renewable energy sources. The invention takes the micro-grid as the research background to develop the P2P energy trade. The P2P energy transaction of the microgrid is mainly divided into microgrid internal energy transaction and microgrid external energy transaction. The participating main bodies of the internal energy trading of the micro-grid comprise micro-grid operators, producers and consumers. Wherein the producers and consumers are simply referred to as users. The participation subject of the external energy trading of the micro-grid is the micro-grid operator of each micro-grid. The internal microgrid transaction is mainly considered, and the transaction is not particularly described below and is the internal microgrid transaction.
In order to make the aforementioned objects, features and advantages of the present invention more comprehensible, the present invention is described in detail with reference to the accompanying drawings and the detailed description thereof.
As shown in fig. 1, the P2P energy trading method based on intelligent contracts provided by the invention comprises the following steps:
s1, aiming at internal transaction of the microgrid, calling an intelligent contract function to register the microgrid with the serial number id, registering users, namely a producer and a consumer under the microgrid, initializing the microgrid and the users at the same time, and constructing a P2P energy transaction model between the producer and the consumer based on an intelligent contract; the method specifically comprises the following steps:
the selling price and the purchasing price of the micro-grid energy with the serial number id are respectively SP
id 、BP
id (ii) a And setting a microgrid id of m
id Individual person of birth and consumption, n
id The set of consumers and the set of the producers and the consumers
Collection for consumer
Respectively indicating the person of birth and consumption
The selling price and the amount of the energy sold, wherein i is 1, 2.
Respectively represent consumers
The purchase price and the amount of energy purchased, where j is 1, 2.
S2, performing P2P energy trading between the prosumers and the consumers by adopting a P2P energy trading model between the prosumers and the consumers by adopting a PC-DA (personal computer-data acquisition), and generating a trading order;
s3, automatically clearing the generated trade order under the intelligent contract;
s4, after the matching of the trading orders is completed, calculating feedback values of all the producers and consumers participating in the current round of trading, and performing user feedback analysis;
and S5, after the set time is reached, the node responsible for packaging packs the generated transaction orders into blocks, then the blocks are transmitted in the network, and after the consensus node reaches consensus, the blocks are linked up, so that the round of transaction is completed.
A price-constrained two-way auction (PC-DA for short) adds price limit in the two-way auction, and the user can not participate in energy transaction when the user exceeds the range of bid. And P2P energy trading between the producer and consumer and the consumer is carried out by adopting a PC-DA inside the microgrid, and the PC-DA considers the bidding of two trading parties and also considers the energy quantity. The patients with either birth or death are classified into 3 categories: the 1 st production energy is totally used by oneself, the 2 nd production energy is sold with surplus energy besides self-use, and the 3 rd production energy is sold totally. Assuming that all the producers and consumers in the micro-grid carry out P2P energy trading in the consumer type, the PC-DA is the consumer and cannot generate a matching order. Assuming that some or all of the producers and consumers inside the microgrid are performing P2P energy transactions as producer types, the PC-DA has both producers and consumers and may generate matching orders. Therefore, the invention assumes that the producer inside the microgrid is a category 2 producer, i.e. the producer sells the surplus energy while using the producer for the energy trade. The producers and consumers are divided into three categories, the first category of energy is totally self-used, the second category of energy is sold as surplus energy except self-use, and the third category of energy is sold as whole. And (4) assuming that the producer and the consumer inside the microgrid are second-class users, and selling redundant energy as the producer while using the consumers to participate in energy trading.
In step S2, the P2P energy trading model between the producer and the consumer adopts PC-DA to trade the P2P energy between the producer and the consumer, and generates a trading order, which specifically includes:
the patients of both birth and consumption
Invoking intelligent contract function publishing
And
then automatically triggers a sort rule according to
Adding the selling arrays in a sequence from low to high;
at the same time, the consumer invokes the intelligent contract function
Issue a publication
And
and judge the consumers
Whether there are sufficient token purchases of
If there are enough tokens, automatically triggers a sort rule according to
Add purchase array in high to low order, otherwise refuse consumer
Participating in the energy transaction of the current round;
generating a trade order according to one-to-one matching of the selling array and the purchasing array and meeting the conditions, and specifically comprising the following steps:
determining the selling price of the first element of the selling array, the quantity of the selling energy and the purchasing price of the first element of the purchasing arrayThe grid and the amount of energy purchased meet the requirements, i.e. both
And
and forming a matched trading order by the two trading parties meeting the requirement, then sequentially iterating until the conditions are not met, and trading the remaining unmatched users with the microgrid operator.
The choice of clearing mechanism determines the transaction price of both parties to the transaction. The microgrid operator can decide the clearing mechanism of the microgrid, and in order to research the influence of different clearing mechanisms on the feedback value of the user, two clearing mechanisms are tried to be adopted for clearing, namely an average price clearing mechanism and a mixed price clearing mechanism.
In the present invention, the step S3, automatically clearing the generated trade order under the intelligent contract, specifically includes:
s301, taking an intelligent contract standard ERC20 as a basic agreement, converting the token and the energy price by adopting an exchange rate, wherein the average price and the mixed price refer to real world currency, the token needs to be converted before settlement, and the exchange mechanism is shown as a formula (1):
token=token_rate*price (1)
wherein token represents token, token _ rate represents exchange rate, and price represents currency;
s302, setting the average price clearing mechanism time to be 1 hour, and adopting average price clearing when the P2P energy transaction is finished in the mode; when the producer bid and the consumer bid are the same, then the average price equals the producer bid and the consumer bid; when the producer and consumer bid is larger than the consumer bid, a matching order cannot be formed; when the producer and the consumer bid less than the consumer bid, clearing according to the average price of the producer and the consumer; wherein the average price
The patients with the symptoms of both birth and consumption
Is/are as follows
And consumers
Is/are as follows
The average value of the two is shown in formula (2):
s303, the mixed price (Mp) refers to a mixed price obtained by comprehensively considering the bids of both producer and consumer, consumer and microgrid, and the price indicates that the mixed price is related to not only the bids of producer and consumer, but also the selling price and purchasing price of microgrid operator. Setting the mixed price clearing mechanism time to be 1 hour, adopting the mixed price clearing to clear the P2P energy source transaction in the mode, and leading the producers and the consumers to be on production and consumption
And consumers
Mixed price of transaction
As shown in formula (3):
in step S4, after the matching of the trade order is completed, feedback values of all the producers and consumers participating in the current round of trade are calculated, and the user feedback analysis is performed, which specifically includes:
s401, calculating the yield of the producers and the consumers: the producer and the consumer are used as special users of the micro-grid, can sell redundant energy to other users while producing and using; thus, the revenue of the producer and the consumer as the producer includes the income of selling energy to users inside the microgrid, operators of the microgrid and the expenditure of investing related equipment; the income of the producer and the consumer is consistent with that of the ordinary consumer, and the income of the consumer is specifically referred; either of the two patients M
iid As a benefit of the producer
As shown in formula (4):
in the formula (I), the compound is shown in the specification,
respectively representing producers and consumers under the id of the microgrid
And consumers
Energy quantity of trading, microgrid operator trading; p is a radical of
ij The person who is born and goes bad
And consumers
The bargain price of (c); the expenditure of the producer and the consumer on the relevant equipment cannot be measured by an accurate value due to the particularity of the producer and the consumer, and therefore, the relation between the produced energy and the equipment expenditure is described by an ln function;
s402, calculating consumer income: the consumer acts as a microgridSimilar to ordinary users, the energy can only be purchased but not produced; the consumer's revenue includes the benefits of the consumer's purchase of energy and the expenditure of energy from the producer or consumer or the microgrid operator. Consumers
Gain of (2)
As shown in formula (5):
in the formula (I), the compound is shown in the specification,
representing consumers
Benefits from purchasing energy;
respectively represent consumers
The benefit factor of (2);
respectively representing consumers under the microgrid id
The syndrome of labor and consumption
Energy quantity of trading, microgrid operator trading; because each consumer has different preference to energy and may have different benefits for purchasing the same energy, for the convenience of calculation, a quadratic function is used to describe the relationship between the energy purchased by the consumer and the obtained benefits, and the quadratic function is used to describe the relationship between the energy purchased by the consumer and the obtained benefits
Representing consumers
The benefit factor of (1);
at S403, the user feedback refers to the satisfaction degree of the user participating in the P2P energy transaction for the transaction after the transaction is finished. User feedback includes two categories, namely, both prenatal and consumer feedback. The feedback of the producers and the consumers is divided into three parts, namely price feedback, energy transaction quantity feedback and income feedback. Calculating a feedback value of the birth and consumption person: the patients of both birth and consumption
Is fed back to
As shown in formula (6):
in the formula (I), the compound is shown in the specification,
respectively indicating the person of birth and consumption
The price feedback value, the energy transaction quantity feedback value and the income feedback value;
the preference coefficient is represented.
S404, calculating a consumer feedback value: consumers
Is fed back to
As shown in formula (7):
in the formula (I), the compound is shown in the specification,
respectively represent consumers
The price feedback value, the energy transaction quantity feedback value and the income feedback value;
the preference coefficient is represented.
And finally, grading the user feedback, wherein the grading of the user feedback is divided into four levels, namely very satisfactory, generally satisfactory and unsatisfactory grades. A lower user feedback value indicates a higher degree of user satisfaction with the current round of transaction.
And according to the construction of the P2P energy transaction model in the step S1, the energy transaction model is programmed into a block chain intelligent contract, so that the automatic clearing of the transaction and the feedback value measurement of the user are realized. Then the energy trading framework diagram of P2P based on smart contracts is shown in fig. 2.
The P2P energy trading model based on the intelligent contract is mainly divided into the following five core functions, namely creating, trading, feedback, inquiry and clearing functions.
Registering: the registration function refers to registering the microgrid, the producer and consumer, and the consumer. The registration of the microgrid can only be completed by a contract creator, and the address of a microgrid operator is designated; the registration of the producer and consumer is called user registration, the user registration must be completed by the contract creator, and the user type (producer or consumer), the number of the affiliated microgrid and the user address are specified when the user is registered. And (3) checking whether the microgrid exists or not while registering the microgrid, if so, returning a microgrid existing mark, and if not, initializing the microgrid. Similarly, the user is registered, and whether the subordinate microgrid and the user exist or not is checked, if the subordinate microgrid does not exist or the user exists, a 'microgrid does not exist' or 'user exists' mark is returned; and if the micro-grid exists and the user does not exist, initializing the user.
Trading: the transaction function refers to the mutual transaction between the participating main bodies, which mainly comprises the transaction between the producer and the consumer, the transaction between the producer and the consumer and the transaction between the consumer and the consumer. Inside the microgrid, the producers and consumers release the quantity and price of the self-sold and purchased energy, and trade orders are matched according to the PC-DA principle. Under the condition that the supply of the P2P energy trading market is excessive or the demand is insufficient, both the producer and the consumer can trade the energy with the microgrid operator, and the trading price is set according to the microgrid operator.
And (3) feedback: the feedback function refers to the satisfaction degree generated by the producer or consumer who completes the round of P2P energy transaction according to the matching order in the transaction process inside the microgrid. The satisfaction degree is measured by adopting a feedback value and is fed back to the microgrid operator after the transaction is finished, and the microgrid operator can check the feedback values of all users.
And (3) inquiring: the inquiry function refers to that all participating parties can inquire about the content related to the energy trading, including the selling price and the purchasing price of the microgrid operator, the user feedback value, the quantity and the price of the energy purchased and sold by the participating parties, the matching trading order and the like.
Clearing: the clearing function is that after the internal transaction of the micro-grid or the external transaction of the micro-grid is completed, the amount is calculated according to a specified clearing mechanism, and the money is automatically cleared after the money is converted into the token. The invention relates to an energy clearing method, which comprises the steps of paying after using energy, automatically checking whether the balance of a participating main body is enough to pay according to the purchased energy quantity by an intelligent contract before the participating main body auctions energy, forbidding the participating of energy transaction if the balance is not enough, allowing the participating of energy transaction if the balance is enough, and simultaneously freezing a corresponding token. The payment process of the energy transaction is automatically completed by the intelligent contract, so that the phenomenon that the participating main body does not pay for the energy or the balance of the energy is insufficient is avoided.
The intelligent contract based on the intelligent contract P2P energy transaction method provided by the invention takes the intelligent contract of the block chain as an important component part of the P2P energy transaction, plays an important role in the transaction between a producer and a consumer, and brings a series of advantages to the P2P energy transaction:
1) the traditional trading mode of the power grid needs a completely trusted third party intermediary as a trading center, and the invention adopts a block chain and intelligent contract mode to ensure that nodes added into the block chain can unconditionally trust each other, thereby achieving the aim of decentralization;
2) the P2P energy transaction between the producer and consumer can not only locally consume renewable energy and reduce the loss in the transmission process, but also has larger profit for the producer and consumer in the P2P energy transaction compared with the traditional energy transaction mode;
3) the P2P energy trading model is deployed on the intelligent contract, users with demand trading can register and join in energy trading and issue own demands, and the users only need to wait for the intelligent contract to match the contract without human intervention, so that a large amount of manpower, material resources and financial resources are saved;
4) the automatic clearing function saves a great deal of time, and two transaction parties do not need to worry about the condition that energy is not used or the condition that energy cannot be used after payment;
5) user feedback values are set in the intelligent contract to measure the satisfaction degree of the user to the transaction, so that a microgrid operator can well master the energy transaction condition of the user;
6) the trade orders are finally stored on the blockchain, the property of the blockchain enables the trade information not to be falsified, and all users can conveniently and timely trace back the trade orders.
The principles and embodiments of the present invention have been described herein using specific examples, which are provided only to help understand the method and the core concept of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, the specific embodiments and the application range may be changed. In view of the above, the present disclosure should not be construed as limiting the invention.