instantswap

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: ISC Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrListenerAlreadyExist = "listener_already_exist"
)
View Source
const (
	LastSyncedTimestampConfigKey = "instantswap_last_synced_timestamp"
)

Variables

This section is empty.

Functions

func GetInstantExchangePrivKey added in v1.1.0

func GetInstantExchangePrivKey(server Server) (string, bool)

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type ExchangeConfig

type ExchangeConfig struct {
	Debug     bool
	APIKey    string
	APISecret string
	// AffiliateID is used to earn refer coin from transaction
	AffiliateID string
	UserID      string
}

ExchangeConfig

type ExchangeServer

type ExchangeServer struct {
	Server Server
	Config ExchangeConfig
}

type InstantSwap

type InstantSwap struct {
	SchedulerCtx           context.Context
	CancelOrderScheduler   context.CancelFunc
	CancelOrderSchedulerMu sync.RWMutex
	SchedulerStartTime     time.Time
	// contains filtered or unexported fields
}

func NewInstantSwap

func NewInstantSwap(db *storm.DB) (*InstantSwap, error)

func (*InstantSwap) AddNotificationListener

func (instantSwap *InstantSwap) AddNotificationListener(notificationListener *OrderNotificationListener, uniqueIdentifier string) error

func (*InstantSwap) CreateOrder

func (instantSwap *InstantSwap) CreateOrder(exchangeObject instantswap.IDExchange, params Order) (*Order, error)

func (*InstantSwap) DeleteOrder

func (instantSwap *InstantSwap) DeleteOrder(order *Order) error

func (*InstantSwap) DeleteOrders

func (instantSwap *InstantSwap) DeleteOrders() error

DeleteOrders deletes all orders saved to the DB.

func (*InstantSwap) ExchangeServers

func (instantSwap *InstantSwap) ExchangeServers() []ExchangeServer

func (*InstantSwap) GetExchangeRateInfo

func (instantSwap *InstantSwap) GetExchangeRateInfo(exchangeObject instantswap.IDExchange, params instantswap.ExchangeRateRequest) (*instantswap.ExchangeRateInfo, error)

func (*InstantSwap) GetLastSyncedTimeStamp

func (instantSwap *InstantSwap) GetLastSyncedTimeStamp() int64

func (*InstantSwap) GetOrderByIDRaw

func (instantSwap *InstantSwap) GetOrderByIDRaw(orderID int) (*Order, error)

GetOrderByIDRaw fetches and returns a single order specified by it's ID

func (*InstantSwap) GetOrderByUUIDRaw

func (instantSwap *InstantSwap) GetOrderByUUIDRaw(orderUUID string) (*Order, error)

GetOrderByUUIDRaw fetches and returns a single order specified by it's UUID.

func (*InstantSwap) GetOrderInfo

func (instantSwap *InstantSwap) GetOrderInfo(exchangeObject instantswap.IDExchange, orderUUID string) (*Order, error)

func (*InstantSwap) GetOrdersRaw

func (instantSwap *InstantSwap) GetOrdersRaw(offset, limit int32, newestFirst bool, server, txID string, status ...instantswap.Status) ([]*Order, error)

GetOrdersRaw fetches and returns all saved orders. If status is specified, only orders with that status will be returned. status is made optional to the sync functionality can update all orders.

func (*InstantSwap) IsSyncing

func (instantSwap *InstantSwap) IsSyncing() bool

func (*InstantSwap) NewExchangeServer

func (instantSwap *InstantSwap) NewExchangeServer(exchangeServer ExchangeServer) (instantswap.IDExchange, error)

NewExchangeServer sets up a new exchange server for use.

func (*InstantSwap) PublishOrderSchedulerEnded

func (instantSwap *InstantSwap) PublishOrderSchedulerEnded()

func (*InstantSwap) PublishOrderSchedulerStarted

func (instantSwap *InstantSwap) PublishOrderSchedulerStarted()

func (*InstantSwap) RemoveNotificationListener

func (instantSwap *InstantSwap) RemoveNotificationListener(uniqueIdentifier string)

func (*InstantSwap) StopSync

func (instantSwap *InstantSwap) StopSync()

func (*InstantSwap) Sync

func (instantSwap *InstantSwap) Sync()

Sync synchronizes the exchange orders, by looping through each exchange server and querying the order info and updating the order saved in the databse with the order returned from the order info query. MUST be called from a goroutine.

func (*InstantSwap) UpdateOrder

func (instantSwap *InstantSwap) UpdateOrder(order *Order) error

UpdateOrder updates an order in the database.

type Order

type Order struct {
	ID                       int            `storm:"id,increment"`
	UUID                     string         `storm:"unique" json:"uuid"`
	Server                   Server         `json:"server" storm:"index"`         // Legacy Exchange Server field, used to update the new ExchangeServer field
	ExchangeServer           ExchangeServer `json:"exchangeServer" storm:"index"` // New Exchange Server field
	SourceWalletID           int            `json:"sourceWalletID"`
	SourceAccountNumber      int32          `json:"sourceAccountNumber"`
	DestinationWalletID      int            `json:"destinationWalletID"`
	DestinationAccountNumber int32          `json:"destinationAccountNumber"`

	OrderedAmount  float64 `json:"orderedAmount"`
	InvoicedAmount float64 `json:"invoicedAmount"`
	ReceiveAmount  float64 `json:"receiveAmount"`
	TxID           string  `json:"txid"`

	FromCurrency string `json:"fromCurrency"`
	ToCurrency   string `json:"toCurrency"`
	FromNetwork  string `json:"fromNetwork"`
	ToNetwork    string `json:"toNetwork"`
	Provider     string `json:"provider"`

	DepositAddress     string  `json:"depositAddress"`     // Address where funds that need to be exchanged should be sent to
	RefundAddress      string  `json:"refundAddress"`      // Address where funds are returned to if the exchange fails
	DestinationAddress string  `json:"destinationAddress"` // Address where successfully converted funds would be sent to
	ExchangeRate       float64 `json:"exchangeRate"`
	ChargedFee         float64 `json:"chargedFee"`

	Confirmations string             `json:"confirmations"`
	Status        instantswap.Status `json:"status" storm:"index"`
	ExpiryTime    int                `json:"expiryTime"` // in seconds
	CreatedAt     int64              `storm:"index" json:"createdAt"`
	LastUpdate    string             `json:"lastUpdate"` // should be timestamp (api currently returns string)

	ExtraID string `json:"extraId"` // changenow.io requirement //changelly payinExtraId value
	UserID  string `json:"userId"`  // changenow.io partner requirement

	Signature string `json:"signature"` // evercoin requirement
}

type OrderNotificationListener

type OrderNotificationListener struct {
	OnExchangeOrdersSynced  func()
	OnOrderCreated          func(order *Order)
	OnOrderSchedulerStarted func()
	OnOrderSchedulerEnded   func()
}

type SchedulerParams

type SchedulerParams struct {
	Order Order

	Frequency         time.Duration // in hours
	BalanceToMaintain float64
	// MaxDeviationRate is the maximum deviation rate allowed between
	// the exchange server rate and the market rate. If the deviation
	// rate is greater than the MaxDeviationRate, the order is not created
	MaxDeviationRate float64

	SpendingPassphrase string
}

type Server

type Server string
const (
	Changelly  Server = "changelly"
	ChangeNow  Server = "changenow"
	CoinSwitch Server = "coinswitch"
	FlypMe     Server = "flypme"
	GoDex      Server = "godex"
	SimpleSwap Server = "simpleswap"
	SwapZone   Server = "swapzone"
	Trocador   Server = "trocador"
)

func (Server) CapFirstLetter

func (es Server) CapFirstLetter() string

CapFirstLetter capitalizes the first letter of the Server

func (Server) ToString

func (es Server) ToString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL