mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-22 14:30:51 -04:00
test clone grpc api with new post offer config
This commit is contained in:
parent
5764a1959f
commit
0cd3c54e37
2 changed files with 117 additions and 60 deletions
|
@ -24,6 +24,27 @@ import { GetTradeStatisticsClient, GetVersionClient, AccountClient, XmrConnectio
|
|||
import { GetTradeStatisticsRequest, GetTradeStatisticsReply, GetVersionRequest, GetVersionReply, IsAppInitializedRequest, IsAppInitializedReply, RegisterDisputeAgentRequest, UnregisterDisputeAgentRequest, MarketPriceRequest, MarketPriceReply, MarketPricesRequest, MarketPricesReply, MarketPriceInfo, MarketDepthRequest, MarketDepthReply, MarketDepthInfo, GetBalancesRequest, GetBalancesReply, XmrBalanceInfo, GetMyOfferRequest, GetMyOfferReply, GetOffersRequest, GetOffersReply, OfferInfo, GetPaymentMethodsRequest, GetPaymentMethodsReply, GetPaymentAccountFormRequest, CreatePaymentAccountRequest, ValidateFormFieldRequest, CreatePaymentAccountReply, GetPaymentAccountFormReply, GetPaymentAccountsRequest, GetPaymentAccountsReply, CreateCryptoCurrencyPaymentAccountRequest, CreateCryptoCurrencyPaymentAccountReply, DeletePaymentAccountRequest, DeletePaymentAccountReply, PostOfferRequest, PostOfferReply, CancelOfferRequest, TakeOfferRequest, TakeOfferReply, TradeInfo, GetTradeRequest, GetTradeReply, GetTradesRequest, GetTradesReply, GetXmrSeedRequest, GetXmrSeedReply, GetXmrPrimaryAddressRequest, GetXmrPrimaryAddressReply, GetXmrNewSubaddressRequest, GetXmrNewSubaddressReply, ConfirmPaymentSentRequest, ConfirmPaymentReceivedRequest, CompleteTradeRequest, XmrTx, GetXmrTxsRequest, GetXmrTxsReply, XmrDestination, CreateXmrTxRequest, CreateXmrTxReply, RelayXmrTxRequest, RelayXmrTxReply, CreateAccountRequest, AccountExistsRequest, AccountExistsReply, DeleteAccountRequest, OpenAccountRequest, IsAccountOpenRequest, IsAccountOpenReply, CloseAccountRequest, ChangePasswordRequest, BackupAccountRequest, BackupAccountReply, RestoreAccountRequest, StopRequest, NotificationMessage, RegisterNotificationListenerRequest, SendNotificationRequest, UrlConnection, AddConnectionRequest, RemoveConnectionRequest, GetConnectionRequest, GetConnectionsRequest, SetConnectionRequest, CheckConnectionRequest, CheckConnectionsReply, CheckConnectionsRequest, StartCheckingConnectionRequest, StopCheckingConnectionRequest, GetBestConnectionRequest, SetAutoSwitchRequest, GetAutoSwitchRequest, CheckConnectionReply, GetConnectionsReply, GetConnectionReply, GetBestConnectionReply, GetDisputeRequest, GetDisputeReply, GetDisputesRequest, GetDisputesReply, OpenDisputeRequest, ResolveDisputeRequest, SendDisputeChatMessageRequest, SendChatMessageRequest, GetChatMessagesRequest, GetChatMessagesReply, StartXmrNodeRequest, StopXmrNodeRequest, IsXmrNodeOnlineRequest, IsXmrNodeOnlineReply, GetXmrNodeSettingsRequest, GetXmrNodeSettingsReply } from "./protobuf/grpc_pb";
|
||||
import { TradeStatistics3, OfferDirection, PaymentMethod, PaymentAccountForm, PaymentAccountFormField, PaymentAccount, PaymentAccountPayload, AvailabilityResult, Attachment, DisputeResult, Dispute, ChatMessage, XmrNodeSettings } from "./protobuf/pb_pb";
|
||||
|
||||
|
||||
/**
|
||||
* Configuration to post, clone, or edit an offer.
|
||||
*/
|
||||
export interface OfferConfig {
|
||||
direction?: OfferDirection;
|
||||
amount?: bigint;
|
||||
minAmount?: bigint;
|
||||
assetCode?: string;
|
||||
paymentAccountId?: string;
|
||||
securityDepositPct?: number;
|
||||
price?: number;
|
||||
marketPriceMarginPct?: number;
|
||||
triggerPrice?: number;
|
||||
reserveExactAmount?: boolean;
|
||||
isPrivateOffer?: boolean;
|
||||
buyerAsTakerWithoutDeposit?: boolean;
|
||||
extraInfo?: string;
|
||||
sourceOfferId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Haveno daemon client.
|
||||
*/
|
||||
|
@ -1035,53 +1056,44 @@ export default class HavenoClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Post an offer.
|
||||
* Post or clone an offer.
|
||||
*
|
||||
* @param {OfferDirection} direction - "buy" or "sell" XMR
|
||||
* @param {bigint} amount - amount of XMR to trade
|
||||
* @param {string} assetCode - asset code to trade for XMR
|
||||
* @param {string} paymentAccountId - payment account id
|
||||
* @param {number} securityDepositPct - security deposit as % of trade amount for buyer and seller
|
||||
* @param {number} price - trade price (optional, default to market price)
|
||||
* @param {number} marketPriceMarginPct - if using market price, % from market price to accept (optional, default 0%)
|
||||
* @param {number} triggerPrice - price to remove offer (optional)
|
||||
* @param {bigint} minAmount - minimum amount to trade (optional, default to fixed amount)
|
||||
* @param {number} reserveExactAmount - reserve exact amount needed for offer, incurring on-chain transaction and 10 confirmations before the offer goes live (default = false)
|
||||
* @param {boolean} isPrivateOffer - whether the offer is private (default = false)
|
||||
* @param {boolean} buyerAsTakerWithoutDeposit - waive buyer as taker deposit and fee (default false)
|
||||
* @param {string} extraInfo - extra information to include with the offer (optional)
|
||||
* @param {OfferConfig} config - configures the offer to post or clone
|
||||
* @param {OfferDirection} [config.direction] - specifies to buy or sell xmr (default buy)
|
||||
* @param {bigint} [config.amount] - amount of XMR to trade
|
||||
* @param {string} [config.assetCode] - asset code to trade for XMR
|
||||
* @param {string} [config.paymentAccountId] - payment account id
|
||||
* @param {number} [config.securityDepositPct] - security deposit as % of trade amount for buyer and seller
|
||||
* @param {number} [config.price] - trade price (optional, default to market price)
|
||||
* @param {number} [config.marketPriceMarginPct] - if using market price, % from market price to accept (optional, default 0%)
|
||||
* @param {number} [config.triggerPrice] - price to remove offer (optional)
|
||||
* @param {bigint} [config.minAmount] - minimum amount to trade (optional, default to fixed amount)
|
||||
* @param {number} [config.reserveExactAmount] - reserve exact amount needed for offer, incurring on-chain transaction and 10 confirmations before the offer goes live (default = false)
|
||||
* @param {boolean} [config.isPrivateOffer] - whether the offer is private (default = false)
|
||||
* @param {boolean} [config.buyerAsTakerWithoutDeposit] - waive buyer as taker deposit and fee (default false)
|
||||
* @param {string} [config.extraInfo] - extra information to include with the offer (optional)
|
||||
* @param {string} [config.sourceOfferId] - create a clone of a source offer which shares the same reserved funds. overrides other fields which are immutable or unspecified (optional)
|
||||
* @return {OfferInfo} the posted offer
|
||||
*/
|
||||
async postOffer(direction: OfferDirection,
|
||||
amount: bigint,
|
||||
assetCode: string,
|
||||
paymentAccountId: string,
|
||||
securityDepositPct: number,
|
||||
price?: number,
|
||||
marketPriceMarginPct?: number,
|
||||
triggerPrice?: number,
|
||||
minAmount?: bigint,
|
||||
reserveExactAmount?: boolean,
|
||||
isPrivateOffer?: boolean,
|
||||
buyerAsTakerWithoutDeposit?: boolean,
|
||||
extraInfo?: string): Promise<OfferInfo> {
|
||||
console.log("Posting offer with security deposit %: " + securityDepositPct)
|
||||
async postOffer(config: OfferConfig): Promise<OfferInfo> {
|
||||
console.log("Posting offer with security deposit %: " + config.securityDepositPct)
|
||||
try {
|
||||
const request = new PostOfferRequest()
|
||||
.setDirection(direction === OfferDirection.BUY ? "buy" : "sell")
|
||||
.setAmount(amount.toString())
|
||||
.setCurrencyCode(assetCode)
|
||||
.setPaymentAccountId(paymentAccountId)
|
||||
.setSecurityDepositPct(securityDepositPct)
|
||||
.setUseMarketBasedPrice(price === undefined)
|
||||
.setMinAmount(minAmount ? minAmount.toString() : amount.toString());
|
||||
if (price) request.setPrice(price.toString());
|
||||
if (marketPriceMarginPct) request.setMarketPriceMarginPct(marketPriceMarginPct);
|
||||
if (triggerPrice) request.setTriggerPrice(triggerPrice.toString());
|
||||
if (reserveExactAmount) request.setReserveExactAmount(true);
|
||||
if (isPrivateOffer) request.setIsPrivateOffer(true);
|
||||
if (buyerAsTakerWithoutDeposit) request.setBuyerAsTakerWithoutDeposit(true);
|
||||
if (extraInfo) request.setExtraInfo(extraInfo);
|
||||
const request = new PostOfferRequest();
|
||||
if (config.direction) request.setDirection(config.direction === OfferDirection.BUY ? "buy" : "sell");
|
||||
if (config.amount) request.setAmount(config.amount.toString());
|
||||
request.setMinAmount(config.minAmount ? config.minAmount.toString() : config.amount!.toString());
|
||||
if (config.assetCode) request.setCurrencyCode(config.assetCode);
|
||||
if (config.paymentAccountId) request.setPaymentAccountId(config.paymentAccountId);
|
||||
if (config.securityDepositPct) request.setSecurityDepositPct(config.securityDepositPct);
|
||||
request.setUseMarketBasedPrice(config.price === undefined);
|
||||
if (config.price) request.setPrice(config.price?.toString())
|
||||
if (config.marketPriceMarginPct) request.setMarketPriceMarginPct(config.marketPriceMarginPct);
|
||||
if (config.triggerPrice) request.setTriggerPrice(config.triggerPrice.toString());
|
||||
if (config.reserveExactAmount) request.setReserveExactAmount(true);
|
||||
if (config.isPrivateOffer) request.setIsPrivateOffer(true);
|
||||
if (config.buyerAsTakerWithoutDeposit) request.setBuyerAsTakerWithoutDeposit(true);
|
||||
if (config.extraInfo) request.setExtraInfo(config.extraInfo);
|
||||
if (config.sourceOfferId) request.setSourceOfferId(config.sourceOfferId);
|
||||
return (await this._offersClient.postOffer(request, {password: this._password})).getOffer()!;
|
||||
} catch (e: any) {
|
||||
throw new HavenoError(e.message, e.code);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue