2021-07-29 08:19:52 -07:00
|
|
|
|
# # ⚠ Warning
|
|
|
|
|
#
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
|
|
|
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
|
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
#
|
|
|
|
|
# [🥭 Mango Markets](https://mango.markets/) support is available at:
|
|
|
|
|
# [Docs](https://docs.mango.markets/)
|
|
|
|
|
# [Discord](https://discord.gg/67jySBhxrg)
|
|
|
|
|
# [Twitter](https://twitter.com/mangomarkets)
|
|
|
|
|
# [Github](https://github.com/blockworks-foundation)
|
|
|
|
|
# [Email](mailto:hello@blockworks.foundation)
|
|
|
|
|
|
2021-08-27 12:37:23 -07:00
|
|
|
|
import typing
|
2021-07-29 08:19:52 -07:00
|
|
|
|
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
|
|
from .perpopenorders import PerpOpenOrders
|
2021-08-05 07:35:08 -07:00
|
|
|
|
from .token import Token
|
|
|
|
|
from .tokenvalue import TokenValue
|
2021-07-29 08:19:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 🥭 PerpAccount class
|
|
|
|
|
#
|
|
|
|
|
# Perp accounts aren't directly addressable. They exist as a sub-object of a full Mango `Account` object.
|
|
|
|
|
#
|
|
|
|
|
class PerpAccount:
|
|
|
|
|
def __init__(self, base_position: Decimal, quote_position: Decimal, long_settled_funding: Decimal,
|
2021-08-17 11:42:11 -07:00
|
|
|
|
short_settled_funding: Decimal, bids_quantity: Decimal, asks_quantity: Decimal,
|
|
|
|
|
taker_base: Decimal, taker_quote: Decimal, mngo_accrued: TokenValue,
|
|
|
|
|
open_orders: PerpOpenOrders):
|
2021-07-29 08:19:52 -07:00
|
|
|
|
self.base_position: Decimal = base_position
|
|
|
|
|
self.quote_position: Decimal = quote_position
|
|
|
|
|
self.long_settled_funding: Decimal = long_settled_funding
|
|
|
|
|
self.short_settled_funding: Decimal = short_settled_funding
|
2021-08-17 11:42:11 -07:00
|
|
|
|
self.bids_quantity: Decimal = bids_quantity
|
|
|
|
|
self.asks_quantity: Decimal = asks_quantity
|
|
|
|
|
self.taker_base: Decimal = taker_base
|
|
|
|
|
self.taker_quote: Decimal = taker_quote
|
2021-08-05 07:35:08 -07:00
|
|
|
|
self.mngo_accrued: TokenValue = mngo_accrued
|
2021-07-29 08:19:52 -07:00
|
|
|
|
self.open_orders: PerpOpenOrders = open_orders
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2021-08-27 12:37:23 -07:00
|
|
|
|
def from_layout(layout: typing.Any, open_orders: PerpOpenOrders, mngo_token: Token) -> "PerpAccount":
|
2021-07-29 08:19:52 -07:00
|
|
|
|
base_position: Decimal = layout.base_position
|
|
|
|
|
quote_position: Decimal = layout.quote_position
|
|
|
|
|
long_settled_funding: Decimal = layout.long_settled_funding
|
|
|
|
|
short_settled_funding: Decimal = layout.short_settled_funding
|
2021-08-17 11:42:11 -07:00
|
|
|
|
bids_quantity: Decimal = layout.bids_quantity
|
|
|
|
|
asks_quantity: Decimal = layout.asks_quantity
|
|
|
|
|
taker_base: Decimal = layout.taker_base
|
|
|
|
|
taker_quote: Decimal = layout.taker_quote
|
2021-08-05 07:35:08 -07:00
|
|
|
|
mngo_accrued_raw: Decimal = layout.mngo_accrued
|
|
|
|
|
mngo_accrued: TokenValue = TokenValue(mngo_token, mngo_token.shift_to_decimals(mngo_accrued_raw))
|
2021-07-29 08:19:52 -07:00
|
|
|
|
|
2021-08-17 11:42:11 -07:00
|
|
|
|
return PerpAccount(base_position, quote_position, long_settled_funding, short_settled_funding,
|
|
|
|
|
bids_quantity, asks_quantity, taker_base, taker_quote, mngo_accrued, open_orders)
|
2021-07-29 08:19:52 -07:00
|
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
2021-08-17 11:42:11 -07:00
|
|
|
|
if self.base_position == Decimal(0) and self.quote_position == Decimal(0) and self.long_settled_funding == Decimal(0) and self.short_settled_funding == Decimal(0) and self.mngo_accrued.value == Decimal(0) and self.open_orders.empty:
|
2021-08-03 04:40:00 -07:00
|
|
|
|
return "« 𝙿𝚎𝚛𝚙𝙰𝚌𝚌𝚘𝚞𝚗𝚝 (empty) »"
|
2021-07-29 08:19:52 -07:00
|
|
|
|
open_orders = f"{self.open_orders}".replace("\n", "\n ")
|
|
|
|
|
return f"""« 𝙿𝚎𝚛𝚙𝙰𝚌𝚌𝚘𝚞𝚗𝚝
|
|
|
|
|
Base Position: {self.base_position}
|
|
|
|
|
Quote Position: {self.quote_position}
|
|
|
|
|
Long Settled Funding: {self.long_settled_funding}
|
|
|
|
|
Short Settled Funding: {self.short_settled_funding}
|
2021-08-17 11:42:11 -07:00
|
|
|
|
Bids Quantity: {self.bids_quantity}
|
|
|
|
|
Asks Quantity: {self.asks_quantity}
|
|
|
|
|
Taker Base: {self.taker_base}
|
|
|
|
|
Taker Quote: {self.taker_quote}
|
2021-07-29 08:19:52 -07:00
|
|
|
|
MNGO Accrued: {self.mngo_accrued}
|
|
|
|
|
OpenOrders:
|
|
|
|
|
{open_orders}
|
|
|
|
|
»"""
|