2022-10-25 18:04:12 +00:00
from decouple import config
2024-04-21 21:09:06 +00:00
from decimal import Decimal
2022-01-01 22:34:23 +00:00
from rest_framework import serializers
2022-10-25 18:04:12 +00:00
2024-06-27 16:47:23 +00:00
from . models import MarketTick , Order , Notification
2022-10-02 18:02:35 +00:00
RETRY_TIME = int ( config ( " RETRY_TIME " ) )
2022-10-20 09:56:10 +00:00
2022-10-02 18:02:35 +00:00
2023-11-11 15:48:54 +00:00
class VersionSerializer ( serializers . Serializer ) :
major = serializers . IntegerField ( )
minor = serializers . IntegerField ( )
patch = serializers . IntegerField ( )
2022-10-02 18:02:35 +00:00
class InfoSerializer ( serializers . Serializer ) :
num_public_buy_orders = serializers . IntegerField ( )
num_public_sell_orders = serializers . IntegerField ( )
2022-10-20 09:56:10 +00:00
book_liquidity = serializers . IntegerField (
help_text = " Total amount of BTC in the order book "
)
2023-11-11 15:48:54 +00:00
active_robots_today = serializers . IntegerField ( )
2022-10-20 09:56:10 +00:00
last_day_nonkyc_btc_premium = serializers . FloatField (
help_text = " Average premium (weighted by volume) of the orders in the last 24h "
)
last_day_volume = serializers . FloatField (
help_text = " Total volume in BTC in the last 24h "
)
lifetime_volume = serializers . FloatField (
help_text = " Total volume in BTC since exchange ' s inception "
)
2023-11-13 14:40:47 +00:00
lnd_version = serializers . CharField ( )
cln_version = serializers . CharField ( )
2022-10-02 18:02:35 +00:00
robosats_running_commit_hash = serializers . CharField ( )
alternative_site = serializers . CharField ( )
alternative_name = serializers . CharField ( )
node_alias = serializers . CharField ( )
node_id = serializers . CharField ( )
network = serializers . CharField ( )
2024-02-11 14:57:47 +00:00
min_order_size = serializers . IntegerField ( help_text = " Minimum order size in Sats " )
max_order_size = serializers . IntegerField ( help_text = " Maximum order size in Sats " )
swap_enabled = serializers . BooleanField (
help_text = " Whether the option for onchain swap payouts is available or not "
)
max_swap = serializers . IntegerField (
help_text = " Maximum size for onchain swap payouts in Sats "
)
2022-10-20 09:56:10 +00:00
maker_fee = serializers . FloatField ( help_text = " Exchange ' s set maker fee " )
taker_fee = serializers . FloatField ( help_text = " Exchange ' s set taker fee " )
bond_size = serializers . FloatField ( help_text = " Default bond size (percent) " )
current_swap_fee_rate = serializers . FloatField (
help_text = " Swap fees to perform on-chain transaction (percent) "
)
2023-11-11 15:48:54 +00:00
version = VersionSerializer ( )
notice_severity = serializers . ChoiceField (
choices = [
( " none " , " none " ) ,
( " warning " , " warning " ) ,
( " success " , " success " ) ,
( " error " , " error " ) ,
( " info " , " info " ) ,
]
)
notice_message = serializers . CharField ( )
2022-01-01 22:34:23 +00:00
2022-02-17 19:50:10 +00:00
2022-01-05 00:13:08 +00:00
class ListOrderSerializer ( serializers . ModelSerializer ) :
2022-01-01 22:34:23 +00:00
class Meta :
model = Order
2022-02-17 19:50:10 +00:00
fields = (
" id " ,
" status " ,
" created_at " ,
" expires_at " ,
" type " ,
" currency " ,
" amount " ,
2022-03-21 23:27:36 +00:00
" has_range " ,
" min_amount " ,
" max_amount " ,
2022-02-17 19:50:10 +00:00
" payment_method " ,
" is_explicit " ,
" premium " ,
" satoshis " ,
" maker " ,
" taker " ,
2022-04-29 18:54:20 +00:00
" escrow_duration " ,
2022-10-20 09:56:10 +00:00
" bond_size " ,
2023-10-10 12:47:22 +00:00
" latitude " ,
2023-11-11 15:48:54 +00:00
" longitude " ,
2022-02-17 19:50:10 +00:00
)
2022-01-01 22:34:23 +00:00
2022-10-02 18:02:35 +00:00
# Only used in oas_schemas
class SummarySerializer ( serializers . Serializer ) :
2023-11-16 13:28:53 +00:00
sent_fiat = serializers . FloatField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " same as `amount` (only for buyer) "
2022-10-02 18:02:35 +00:00
)
2023-11-16 13:28:53 +00:00
received_fiat = serializers . FloatField (
required = False , help_text = " same as `amount` (only for seller) "
)
sent_sats = serializers . IntegerField (
required = False , help_text = " The total sats you sent (only for seller) "
)
2022-10-02 18:02:35 +00:00
received_sats = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " same as `trade_satoshis` (only for buyer) "
2022-10-02 18:02:35 +00:00
)
is_swap = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " True if the payout was on-chain (only for buyer) "
2022-10-02 18:02:35 +00:00
)
2023-11-16 13:28:53 +00:00
is_buyer = serializers . BooleanField (
required = False , help_text = " True if the robot is the order buyer "
)
2022-10-02 18:02:35 +00:00
received_onchain_sats = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The on-chain sats received (only for buyer and if `is_swap` is `true`) " ,
2022-10-02 18:02:35 +00:00
)
mining_fee_sats = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Mining fees paid in satoshis (only for buyer and if `is_swap` is `true`) " ,
2022-10-02 18:02:35 +00:00
)
swap_fee_sats = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Exchange swap fee in sats (i.e excluding miner fees) (only for buyer and if `is_swap` is `true`) " ,
2022-10-02 18:02:35 +00:00
)
swap_fee_percent = serializers . FloatField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " same as `swap_fee_rate` (only for buyer and if `is_swap` is `true` " ,
2022-10-02 18:02:35 +00:00
)
2023-11-16 13:28:53 +00:00
bond_size_sats = serializers . IntegerField (
required = False , help_text = " The amount of Satoshis at stake "
2022-10-02 18:02:35 +00:00
)
2023-11-16 13:28:53 +00:00
bond_size_percent = serializers . FloatField (
required = False , help_text = " The relative size of Satoshis at stake "
2022-10-02 18:02:35 +00:00
)
trade_fee_sats = serializers . IntegerField (
required = False ,
2023-11-16 13:28:53 +00:00
help_text = " Exchange fees in sats (does not include swap fee and miner fee) " ,
)
trade_fee_percent = serializers . FloatField (
required = False ,
help_text = " Exchange fees in percent (does not include swap fee and miner fee) " ,
)
payment_hash = serializers . CharField (
required = False , help_text = " The payment_hash of the payout invoice "
)
preimage = serializers . CharField (
required = False ,
help_text = " The preimage of the payout invoice (proof of payment) " ,
2022-10-02 18:02:35 +00:00
)
2023-11-23 17:52:57 +00:00
address = serializers . CharField (
required = False ,
help_text = " The address of the payout if on-the-fly swap was selected " ,
)
txid = serializers . CharField (
required = False ,
help_text = " The transaction hash of the payout if on-the-fly swap was selected " ,
)
2022-10-02 18:02:35 +00:00
# Only used in oas_schemas
class PlatformSummarySerializer ( serializers . Serializer ) :
contract_timestamp = serializers . DateTimeField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Timestamp of when the contract was finalized (price and sats fixed) " ,
2022-10-02 18:02:35 +00:00
)
contract_total_time = serializers . FloatField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The time taken for the contract to complete (from taker taking the order to completion of order) in seconds " ,
2022-10-02 18:02:35 +00:00
)
routing_fee_sats = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Sats payed by the exchange for routing fees. Mining fee in case of on-chain swap payout " ,
2022-10-02 18:02:35 +00:00
)
trade_revenue_sats = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " The sats the exchange earned from the trade "
2022-10-02 18:02:35 +00:00
)
2023-11-16 13:28:53 +00:00
routing_budget_sats = serializers . FloatField (
required = False , help_text = " The budget allocated for routing costs in Satoshis "
)
contract_exchange_rate = serializers . FloatField (
required = False ,
help_text = " The exchange rate applied to this contract. Taken from externals APIs exactly when the taker bond was locked. " ,
)
2022-10-20 09:56:10 +00:00
2022-10-02 18:02:35 +00:00
# Only used in oas_schemas
class OrderDetailSerializer ( serializers . ModelSerializer ) :
total_secs_exp = serializers . IntegerField (
required = False ,
help_text = " Duration of time (in seconds) to expire, according to the current status of order. "
2022-10-20 09:56:10 +00:00
" This is duration of time after `created_at` (in seconds) that the order will automatically expire. "
" This value changes according to which stage the order is in " ,
2022-10-02 18:02:35 +00:00
)
penalty = serializers . DateTimeField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Time when the user penalty will expire. Penalty applies when you create orders repeatedly without commiting a bond " ,
2022-10-02 18:02:35 +00:00
)
is_maker = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Whether you are the maker or not "
2022-10-02 18:02:35 +00:00
)
is_taker = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Whether you are the taker or not "
2022-10-02 18:02:35 +00:00
)
is_participant = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " True if you are either a taker or maker, False otherwise " ,
2022-10-02 18:02:35 +00:00
)
maker_status = serializers . CharField (
required = False ,
help_text = " Status of the maker: \n "
" - ** ' Active ' ** (seen within last 2 min) \n "
" - ** ' Seen Recently ' ** (seen within last 10 min) \n "
" - ** ' Inactive ' ** (seen more than 10 min ago) \n \n "
2022-10-20 09:56:10 +00:00
" Note: When you make a request to this route, your own status get ' s updated and can be seen by your counterparty " ,
2022-10-02 18:02:35 +00:00
)
2023-11-12 12:39:39 +00:00
taker_status = serializers . CharField (
2022-10-02 18:02:35 +00:00
required = False ,
2023-11-12 12:39:39 +00:00
help_text = " Status of the maker: \n "
" - ** ' Active ' ** (seen within last 2 min) \n "
" - ** ' Seen Recently ' ** (seen within last 10 min) \n "
" - ** ' Inactive ' ** (seen more than 10 min ago) \n \n "
" Note: When you make a request to this route, your own status get ' s updated and can be seen by your counterparty " ,
2022-10-02 18:02:35 +00:00
)
2023-11-12 12:39:39 +00:00
price_now = serializers . FloatField (
2022-10-02 18:02:35 +00:00
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Price of the order in the order ' s currency at the time of request (upto 5 significant digits) " ,
2022-10-02 18:02:35 +00:00
)
2023-11-11 15:48:54 +00:00
premium = serializers . CharField (
required = False , help_text = " Premium over the CEX price set by the maker "
)
premium_now = serializers . FloatField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Premium over the CEX price at the current time "
2022-10-02 18:02:35 +00:00
)
2023-11-11 15:48:54 +00:00
premium_percentile = serializers . FloatField (
2022-10-02 18:02:35 +00:00
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " (Only if `is_maker`) Premium percentile of your order compared to other public orders in the same currency currently in the order book " ,
2022-10-02 18:02:35 +00:00
)
num_similar_orders = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " (Only if `is_maker`) The number of public orders of the same currency currently in the order book " ,
2022-10-02 18:02:35 +00:00
)
tg_enabled = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " (Only if `is_maker`) Whether Telegram notification is enabled or not " ,
2022-10-02 18:02:35 +00:00
)
tg_token = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " (Only if `is_maker`) Your telegram bot token required to enable notifications. " ,
2022-10-02 18:02:35 +00:00
)
tg_bot_name = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " (Only if `is_maker`) The Telegram username of the bot " ,
2022-10-02 18:02:35 +00:00
)
is_buyer = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Whether you are a buyer of sats (you will be receiving sats) " ,
2022-10-02 18:02:35 +00:00
)
is_seller = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Whether you are a seller of sats or not (you will be sending sats) " ,
2022-10-02 18:02:35 +00:00
)
maker_nick = serializers . CharField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Nickname (Robot name) of the maker "
2022-10-02 18:02:35 +00:00
)
2023-12-01 12:56:55 +00:00
maker_hash_id = serializers . CharField (
required = False , help_text = " The maker ' s robot hash "
)
2022-10-02 18:02:35 +00:00
taker_nick = serializers . CharField (
2023-12-01 12:56:55 +00:00
required = False , help_text = " The taker ' s robot hash "
)
taker_hash_id = serializers . CharField (
required = False , help_text = " The taker ' s robot hash "
2022-10-02 18:02:35 +00:00
)
status_message = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The current status of the order corresponding to the `status` " ,
2022-10-02 18:02:35 +00:00
)
is_fiat_sent = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Whether or not the fiat amount is sent by the buyer "
2022-10-02 18:02:35 +00:00
)
is_disputed = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Whether or not the counterparty raised a dispute "
2022-10-02 18:02:35 +00:00
)
2022-10-20 09:56:10 +00:00
ur_nick = serializers . CharField ( required = False , help_text = " Your Nickname " )
2022-10-02 18:02:35 +00:00
maker_locked = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " True if maker bond is locked, False otherwise "
2022-10-02 18:02:35 +00:00
)
taker_locked = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " True if taker bond is locked, False otherwise "
2022-10-02 18:02:35 +00:00
)
escrow_locked = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " True if escrow is locked, False otherwise. Escrow is the sats to be sold, held by Robosats until the trade is finised. " ,
2022-10-02 18:02:35 +00:00
)
trade_satoshis = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Seller sees the amount of sats they need to send. Buyer sees the amount of sats they will receive " ,
2022-10-02 18:02:35 +00:00
)
bond_invoice = serializers . CharField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " When `status` = `0`, `3`. Bond invoice to be paid "
2022-10-02 18:02:35 +00:00
)
bond_satoshis = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " The bond amount in satoshis "
2022-10-02 18:02:35 +00:00
)
escrow_invoice = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " For the seller, the escrow invoice to be held by RoboSats " ,
2022-10-02 18:02:35 +00:00
)
escrow_satoshis = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " The escrow amount in satoshis "
2022-10-02 18:02:35 +00:00
)
invoice_amount = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The amount in sats the buyer needs to submit an invoice of to receive the trade amount " ,
2022-10-02 18:02:35 +00:00
)
swap_allowed = serializers . BooleanField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Whether on-chain swap is allowed "
2022-10-02 18:02:35 +00:00
)
swap_failure_reason = serializers . CharField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " Reason for why on-chain swap is not available "
2022-10-02 18:02:35 +00:00
)
2023-11-17 12:57:37 +00:00
suggested_mining_fee_rate = serializers . FloatField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " fee in sats/vbyte for the on-chain swap "
2022-10-02 18:02:35 +00:00
)
2022-10-20 09:56:10 +00:00
swap_fee_rate = serializers . FloatField (
2022-10-02 18:02:35 +00:00
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " in percentage, the swap fee rate the platform charges " ,
2022-10-02 18:02:35 +00:00
)
2023-11-12 12:39:39 +00:00
latitude = serializers . FloatField (
2023-10-10 12:47:22 +00:00
required = False ,
help_text = " Latitude of the order for F2F payments " ,
)
2023-11-12 12:39:39 +00:00
longitude = serializers . FloatField (
2023-10-10 12:47:22 +00:00
required = False ,
help_text = " Longitude of the order for F2F payments " ,
)
2022-10-02 18:02:35 +00:00
pending_cancel = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Your counterparty requested for a collaborative cancel when `status` is either `8`, `9` or `10` " ,
2022-10-02 18:02:35 +00:00
)
asked_for_cancel = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " You requested for a collaborative cancel `status` is either `8`, `9` or `10` " ,
2022-10-02 18:02:35 +00:00
)
statement_submitted = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " True if you have submitted a statement. Available when `status` is `11` " ,
2022-10-02 18:02:35 +00:00
)
retries = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Number of times ln node has tried to make the payment to you (only if you are the buyer) " ,
2022-10-02 18:02:35 +00:00
)
next_retry_time = serializers . DateTimeField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = f " The next time payment will be retried. Payment is retried every { RETRY_TIME } sec " ,
2022-10-02 18:02:35 +00:00
)
failure_reason = serializers . CharField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " The reason the payout failed "
2022-10-02 18:02:35 +00:00
)
invoice_expired = serializers . BooleanField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " True if the payout invoice expired. `invoice_amount` will be re-set and sent which means the user has to submit a new invoice to be payed " ,
2022-10-02 18:02:35 +00:00
)
trade_fee_percent = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The fee for the trade (fees differ for maker and taker) " ,
2022-10-02 18:02:35 +00:00
)
bond_size_sats = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " The size of the bond in sats "
2022-10-02 18:02:35 +00:00
)
bond_size_percent = serializers . IntegerField (
2022-10-20 09:56:10 +00:00
required = False , help_text = " same as `bond_size` "
2022-10-02 18:02:35 +00:00
)
maker_summary = SummarySerializer ( required = False )
taker_summary = SummarySerializer ( required = False )
2023-11-11 15:48:54 +00:00
satoshis_now = serializers . IntegerField (
required = False ,
help_text = " Maximum size of the order right now in Satoshis " ,
)
platform_summary = PlatformSummarySerializer ( required = False )
2022-10-02 18:02:35 +00:00
expiry_message = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The reason the order expired (message associated with the `expiry_reason`) " ,
2022-10-02 18:02:35 +00:00
)
num_satoshis = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " only if status = `14` (Successful Trade) and is_buyer = `true` " ,
2022-10-02 18:02:35 +00:00
)
sent_satoshis = serializers . IntegerField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " only if status = `14` (Successful Trade) and is_buyer = `true` " ,
2022-10-02 18:02:35 +00:00
)
txid = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " Transaction id of the on-chain swap payout. Only if status = `14` (Successful Trade) and is_buyer = `true` " ,
2022-10-02 18:02:35 +00:00
)
network = serializers . CharField (
required = False ,
2022-10-20 09:56:10 +00:00
help_text = " The network eg. ' testnet ' , ' mainnet ' . Only if status = `14` (Successful Trade) and is_buyer = `true` " ,
2022-10-02 18:02:35 +00:00
)
2023-11-14 23:07:28 +00:00
chat_last_index = serializers . IntegerField (
required = False ,
help_text = " The index of the last message sent in the trade chatroom " ,
)
2022-10-02 18:02:35 +00:00
class Meta :
model = Order
fields = (
" id " ,
" status " ,
" created_at " ,
" expires_at " ,
" type " ,
" currency " ,
" amount " ,
" has_range " ,
" min_amount " ,
" max_amount " ,
" payment_method " ,
" is_explicit " ,
" premium " ,
2023-11-11 15:48:54 +00:00
" premium_now " ,
2022-10-02 18:02:35 +00:00
" satoshis " ,
2023-11-11 15:48:54 +00:00
" satoshis_now " ,
2022-10-02 18:02:35 +00:00
" maker " ,
" taker " ,
" escrow_duration " ,
" total_secs_exp " ,
" penalty " ,
" is_maker " ,
" is_taker " ,
" is_participant " ,
" maker_status " ,
" taker_status " ,
" price_now " ,
" premium_percentile " ,
" num_similar_orders " ,
" tg_enabled " ,
" tg_token " ,
" tg_bot_name " ,
" is_buyer " ,
" is_seller " ,
" maker_nick " ,
2023-12-01 12:56:55 +00:00
" maker_hash_id " ,
2022-10-02 18:02:35 +00:00
" taker_nick " ,
2023-12-01 12:56:55 +00:00
" taker_hash_id " ,
2022-10-02 18:02:35 +00:00
" status_message " ,
" is_fiat_sent " ,
" is_disputed " ,
" ur_nick " ,
" ur_nick " ,
" maker_locked " ,
" taker_locked " ,
" escrow_locked " ,
" trade_satoshis " ,
" bond_invoice " ,
" bond_satoshis " ,
" escrow_invoice " ,
" escrow_satoshis " ,
" invoice_amount " ,
" swap_allowed " ,
2022-10-20 09:56:10 +00:00
" swap_failure_reason " ,
2022-10-02 18:02:35 +00:00
" suggested_mining_fee_rate " ,
" swap_fee_rate " ,
" pending_cancel " ,
" asked_for_cancel " ,
" statement_submitted " ,
" retries " ,
" next_retry_time " ,
" failure_reason " ,
" invoice_expired " ,
" public_duration " ,
" bond_size " ,
" trade_fee_percent " ,
" bond_size_sats " ,
" bond_size_percent " ,
" maker_summary " ,
" taker_summary " ,
" platform_summary " ,
" expiry_reason " ,
" expiry_message " ,
" num_satoshis " ,
" sent_satoshis " ,
" txid " ,
" network " ,
2023-10-10 12:47:22 +00:00
" latitude " ,
" longitude " ,
2023-11-14 23:07:28 +00:00
" chat_last_index " ,
2022-10-02 18:02:35 +00:00
)
2024-06-27 16:47:23 +00:00
class ListNotificationSerializer ( serializers . ModelSerializer ) :
2024-06-29 15:09:04 +00:00
status = serializers . SerializerMethodField (
help_text = " The `status` of the order when the notification was trigered " ,
)
2024-06-27 16:47:23 +00:00
class Meta :
model = Notification
2024-06-28 15:16:31 +00:00
fields = ( " title " , " description " , " order_id " , " status " )
2024-06-27 16:47:23 +00:00
2024-06-29 15:09:04 +00:00
def get_status ( self , notification ) - > int :
return notification . order . status
2024-06-27 16:47:23 +00:00
2022-10-02 18:02:35 +00:00
class OrderPublicSerializer ( serializers . ModelSerializer ) :
maker_nick = serializers . CharField ( required = False )
2023-11-28 11:13:40 +00:00
maker_hash_id = serializers . CharField ( required = False )
2022-10-20 09:56:10 +00:00
maker_status = serializers . CharField (
2024-06-02 08:37:38 +00:00
help_text = ' Status of the nick - " Active " , " Seen Recently " or " Inactive " ' ,
required = False ,
2022-10-20 09:56:10 +00:00
)
price = serializers . FloatField (
help_text = " Price in order ' s fiat currency " , required = False
)
satoshis_now = serializers . IntegerField (
help_text = " The amount of sats to be traded at the present moment (not including the fees) " ,
required = False ,
)
2022-10-02 18:02:35 +00:00
class Meta :
model = Order
fields = (
" id " ,
" created_at " ,
" expires_at " ,
" type " ,
" currency " ,
" amount " ,
" has_range " ,
" min_amount " ,
" max_amount " ,
" payment_method " ,
" is_explicit " ,
" premium " ,
" satoshis " ,
" maker " ,
" maker_nick " ,
2023-11-28 11:13:40 +00:00
" maker_hash_id " ,
2022-10-02 18:02:35 +00:00
" maker_status " ,
" price " ,
" escrow_duration " ,
2022-10-16 21:11:48 +00:00
" satoshis_now " ,
2022-10-20 09:56:10 +00:00
" bond_size " ,
2023-10-10 12:47:22 +00:00
" latitude " ,
2023-11-11 15:48:54 +00:00
" longitude " ,
2022-10-02 18:02:35 +00:00
)
2022-01-01 22:34:23 +00:00
class MakeOrderSerializer ( serializers . ModelSerializer ) :
2022-10-02 18:02:35 +00:00
currency = serializers . IntegerField (
required = True ,
2023-05-09 13:07:16 +00:00
help_text = " Currency id. See [here](https://github.com/RoboSats/robosats/blob/main/frontend/static/assets/currencies.json) for a list of all IDs " ,
2022-10-02 18:02:35 +00:00
)
payment_method = serializers . CharField (
max_length = 70 ,
default = " not specified " ,
required = False ,
2023-05-09 13:07:16 +00:00
help_text = " Can be any string. The UI recognizes [these payment methods](https://github.com/RoboSats/robosats/blob/main/frontend/src/components/payment-methods/Methods.js) and displays them with a logo. " ,
2022-10-02 18:02:35 +00:00
)
is_explicit = serializers . BooleanField (
default = False ,
2022-10-20 09:56:10 +00:00
help_text = " Whether the order is explicitly priced or not. If set to `true` then `satoshis` need to be specified " ,
2022-10-02 18:02:35 +00:00
)
has_range = serializers . BooleanField (
default = False ,
2022-10-20 09:56:10 +00:00
help_text = " Whether the order specifies a range of amount or a fixed amount. \n \n If `true`, then `min_amount` and `max_amount` fields are **required**. \n \n If `false` then `amount` is **required** " ,
2022-10-02 18:02:35 +00:00
)
2022-02-17 19:50:10 +00:00
2022-01-01 22:34:23 +00:00
class Meta :
model = Order
2022-02-17 19:50:10 +00:00
fields = (
" type " ,
" currency " ,
" amount " ,
2022-03-21 23:27:36 +00:00
" has_range " ,
" min_amount " ,
" max_amount " ,
2022-02-17 19:50:10 +00:00
" payment_method " ,
" is_explicit " ,
" premium " ,
" satoshis " ,
2022-03-18 21:21:13 +00:00
" public_duration " ,
2022-04-29 18:54:20 +00:00
" escrow_duration " ,
2022-03-18 22:09:38 +00:00
" bond_size " ,
2023-10-10 12:47:22 +00:00
" latitude " ,
2023-11-11 15:48:54 +00:00
" longitude " ,
2022-02-17 19:50:10 +00:00
)
2022-10-20 09:56:10 +00:00
2022-01-06 20:33:40 +00:00
class UpdateOrderSerializer ( serializers . Serializer ) :
2022-10-20 09:56:10 +00:00
invoice = serializers . CharField (
2023-05-17 13:06:04 +00:00
max_length = 15000 ,
allow_null = True ,
allow_blank = True ,
default = None ,
help_text = " Invoice used for payouts. Must be PGP signed with the robot ' s public key. The expected Armored PGP header is -----BEGIN PGP SIGNED MESSAGE----- \n Hash: SHA512 \n \n " ,
2022-10-20 09:56:10 +00:00
)
2022-11-24 17:42:30 +00:00
routing_budget_ppm = serializers . IntegerField (
default = 0 ,
2024-04-21 21:09:06 +00:00
min_value = Decimal ( 0 ) ,
2023-05-01 10:30:53 +00:00
max_value = 100_001 ,
2022-11-24 17:42:30 +00:00
allow_null = True ,
required = False ,
help_text = " Max budget to allocate for routing in PPM " ,
)
2022-10-20 09:56:10 +00:00
address = serializers . CharField (
2023-05-17 13:06:04 +00:00
max_length = 15000 ,
allow_null = True ,
allow_blank = True ,
default = None ,
help_text = " Onchain address used for payouts. Must be PGP signed with the robot ' s public key. The expected Armored PGP header is -----BEGIN PGP SIGNED MESSAGE----- \n Hash: SHA512 \n \n " ,
2022-10-20 09:56:10 +00:00
)
statement = serializers . CharField (
2023-05-01 10:30:53 +00:00
max_length = 500_000 , allow_null = True , allow_blank = True , default = None
2022-10-20 09:56:10 +00:00
)
2022-02-17 19:50:10 +00:00
action = serializers . ChoiceField (
choices = (
2022-04-29 18:54:20 +00:00
" pause " ,
2022-02-17 19:50:10 +00:00
" take " ,
" update_invoice " ,
2022-06-06 20:37:51 +00:00
" update_address " ,
2022-02-17 19:50:10 +00:00
" submit_statement " ,
" dispute " ,
" cancel " ,
" confirm " ,
2023-04-28 09:19:18 +00:00
" undo_confirm " ,
2022-02-17 19:50:10 +00:00
" rate_platform " ,
) ,
allow_null = False ,
)
rating = serializers . ChoiceField (
choices = ( " 1 " , " 2 " , " 3 " , " 4 " , " 5 " ) ,
allow_null = True ,
allow_blank = True ,
default = None ,
)
2022-10-20 09:56:10 +00:00
amount = serializers . DecimalField (
max_digits = 18 , decimal_places = 8 , allow_null = True , required = False , default = None
)
mining_fee_rate = serializers . DecimalField (
max_digits = 6 , decimal_places = 3 , allow_null = True , required = False , default = None
)
2022-03-06 16:08:28 +00:00
class ClaimRewardSerializer ( serializers . Serializer ) :
2022-10-20 09:56:10 +00:00
invoice = serializers . CharField (
max_length = 2000 ,
allow_null = True ,
allow_blank = True ,
default = None ,
help_text = " A valid LN invoice with the reward amount to withdraw " ,
)
2022-03-12 11:24:11 +00:00
class PriceSerializer ( serializers . Serializer ) :
2022-06-21 19:29:07 +00:00
pass
2022-10-20 09:56:10 +00:00
class TickSerializer ( serializers . ModelSerializer ) :
2022-06-21 19:29:07 +00:00
class Meta :
model = MarketTick
fields = (
" timestamp " ,
" currency " ,
" volume " ,
" price " ,
" premium " ,
" fee " ,
)
2023-11-18 16:06:22 +00:00
depth = 0
2022-08-12 17:41:06 +00:00
2022-10-20 09:56:10 +00:00
2022-08-12 17:41:06 +00:00
class StealthSerializer ( serializers . Serializer ) :
wantsStealth = serializers . BooleanField ( )