cxrpc

package
v0.0.0-...-7ad0b1f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 12 Imported by: 0

README

cxrpc

This package handles RPC requests coming in to the exchange. Here are all the commands supported so far: RPC is just a starting point for being able to accept network I/O

register

Register registers an account if that username does not exist already

ocx register name

Arguments:

  • Name (string)

Outputs:

  • A message that says you successfully registered or an error

vieworderbook

Vieworderbook shows you the current orderbook

ocx vieworderbook pair [buy/sell]

Arguments:

  • Asset pair (string)
  • buy or sell (optional string)

Outputs:

  • The orderbook in a nice little command-line table

If you specify buy or sell you will be given only the buy or sell side of the order book for the specified pair.

getprice

Getprice will get the price of a pair, based on midpoint of volume of bids and asks

ocx getprice pair

Arguments:

  • Asset pair (string)

Outputs:

  • The price / conversion rate of the asset

placeorder

This will print a description of the order after making it, and prompt the user before actually sending it.

ocx placeorder name {buy|sell} pair amountHave price

The price is price, amountHave is the amount of the asset you have. If you're on the selling side, that will be the first asset1 in the asset1/asset2 pair. If you're on the buying side, that will be the second, asset2.

Arguments:

  • Name (string)
  • buy or sell (string)
  • Asset pair (string)
  • AmountHave (uint)
  • Price (float)

Outputs:

  • Order submitted successfully (or error)
  • An order ID (or error)

getdepositaddress

Getdepositaddress will return the deposit address that is assigned to the user's account for a certain asset.

ocx getdepositaddress name asset

Arguments

  • Name (string)
  • Asset (string)

Outputs:

  • A deposit address for the specified name and asset (or error)

withdraw

Withdraw will send a withdraw transaction to the blockchain.

ocx withdrawtoaddress name amount asset recvaddress

Arguments:

  • Name (string)
  • Amount (uint, satoshis)
  • Asset (string)
  • Receive address (string)

Outputs:

  • Transaction ID (or error)

getbalance

Getbalance will get your balance

ocx getbalance name asset

Arguments:

  • Name (string)
  • Asset (string)

Outputs:

  • Your balance for specified asset (or error)

getallbalances

Getallbalances will get balances for all of your assets.

ocx getallbalances name

Arguments:

  • Name (string)

Outputs:

  • Balances for all of your assets (or error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelOrderArgs

type CancelOrderArgs struct {
	OrderID   string
	Signature []byte
}

CancelOrderArgs holds the args for the CancelOrder command

type CancelOrderReply

type CancelOrderReply struct {
}

CancelOrderReply holds the args for the CancelOrder command

type GetBalanceArgs

type GetBalanceArgs struct {
	Asset     string
	Signature []byte
}

GetBalanceArgs hold the arguments for GetBalance

type GetBalanceReply

type GetBalanceReply struct {
	Amount uint64
}

GetBalanceReply holds the reply for GetBalance

type GetDepositAddressArgs

type GetDepositAddressArgs struct {
	Asset     string
	Signature []byte
}

GetDepositAddressArgs hold the arguments for GetDepositAddress

type GetDepositAddressReply

type GetDepositAddressReply struct {
	Address string
}

GetDepositAddressReply holds the reply for GetDepositAddress

type GetLitConnectionArgs

type GetLitConnectionArgs struct {
}

GetLitConnectionArgs holds the args for the getlitconnection RPC command

type GetLitConnectionReply

type GetLitConnectionReply struct {
	PubKeyHash string
	Ports      []uint16
}

GetLitConnectionReply holds the reply for the getlitconnection RPC command

type GetOrderArgs

type GetOrderArgs struct {
	OrderID   string
	Signature []byte
}

GetOrderArgs holds the args for the GetOrder command

type GetOrderReply

type GetOrderReply struct {
	Order *match.LimitOrderIDPair
}

GetOrderReply holds the reply for the GetOrder command

type GetOrdersForPubkeyArgs

type GetOrdersForPubkeyArgs struct {
	Signature []byte
}

GetOrdersForPubkeyArgs holds the args for the GetOrdersForPubkey command

type GetOrdersForPubkeyReply

type GetOrdersForPubkeyReply struct {
	Orders []*match.LimitOrderIDPair
}

GetOrdersForPubkeyReply holds the reply for the GetOrdersForPubkey command

type GetPairsArgs

type GetPairsArgs struct {
}

GetPairsArgs holds the args for the GetPairs command

type GetPairsReply

type GetPairsReply struct {
	PairList []string
}

GetPairsReply holds the reply for the GetPairs command

type GetPriceArgs

type GetPriceArgs struct {
	TradingPair *match.Pair
}

GetPriceArgs holds the args for the GetPrice command

type GetPriceReply

type GetPriceReply struct {
	Price float64
}

GetPriceReply holds the reply for the GetPrice command

type GetRegistrationStringArgs

type GetRegistrationStringArgs struct {
}

GetRegistrationStringArgs holds the args for register

type GetRegistrationStringReply

type GetRegistrationStringReply struct {
	RegistrationString string
}

GetRegistrationStringReply holds the data for the register reply

type OpencxClient

type OpencxClient interface {
	// Call calls the service method with a name, arguments, and reply
	Call(string, interface{}, interface{}) error
	// SetupConnection sets up a connection with the server
	SetupConnection(string, uint16) error
}

OpencxClient is an interface defining the methods a client should implement. This could be changed, but right now this is what a client is, and this is what benchclient supports. This abstraction only allows us to use either authenticated or unauthenticated clients.

type OpencxNoiseClient

type OpencxNoiseClient struct {
	Conn *rpc.Client
	// contains filtered or unexported fields
}

OpencxNoiseClient is an authenticated RPC Client for the opencx Server

func (*OpencxNoiseClient) Call

func (cl *OpencxNoiseClient) Call(serviceMethod string, args interface{}, reply interface{}) (err error)

Call calls the servicemethod with name string, args args, and reply reply

func (*OpencxNoiseClient) SetKey

func (cl *OpencxNoiseClient) SetKey(privkey *koblitz.PrivateKey) (err error)

SetKey sets the private key for the noise client.

func (*OpencxNoiseClient) SetupConnection

func (cl *OpencxNoiseClient) SetupConnection(server string, port uint16) (err error)

SetupConnection creates a new RPC Noise client

type OpencxRPC

type OpencxRPC struct {
	Server *cxserver.OpencxServer
}

OpencxRPC is what is registered and called

func (*OpencxRPC) CancelOrder

func (cl *OpencxRPC) CancelOrder(args CancelOrderArgs, reply *CancelOrderReply) (err error)

CancelOrder cancels the order

func (*OpencxRPC) GetBalance

func (cl *OpencxRPC) GetBalance(args GetBalanceArgs, reply *GetBalanceReply) (err error)

GetBalance is the RPC Interface for GetBalance

func (*OpencxRPC) GetDepositAddress

func (cl *OpencxRPC) GetDepositAddress(args GetDepositAddressArgs, reply *GetDepositAddressReply) (err error)

GetDepositAddress is the RPC Interface for GetDepositAddress

func (*OpencxRPC) GetLitConnection

func (cl *OpencxRPC) GetLitConnection(args GetLitConnectionArgs, reply *GetLitConnectionReply) (err error)

GetLitConnection gets a pubkeyhash and port for connecting with lit, the hostname is assumed to be the same.

func (*OpencxRPC) GetOrder

func (cl *OpencxRPC) GetOrder(args GetOrderArgs, reply *GetOrderReply) (err error)

GetOrder gets an order based on orderID

func (*OpencxRPC) GetOrdersForPubkey

func (cl *OpencxRPC) GetOrdersForPubkey(args GetOrdersForPubkeyArgs, reply *GetOrdersForPubkeyReply) (err error)

GetOrdersForPubkey gets the orders for the pubkey which has signed the getOrdersString

func (*OpencxRPC) GetPairs

func (cl *OpencxRPC) GetPairs(args GetPairsArgs, reply *GetPairsReply) (err error)

GetPairs gets all the pairs as nice strings

func (*OpencxRPC) GetPrice

func (cl *OpencxRPC) GetPrice(args GetPriceArgs, reply *GetPriceReply) (err error)

GetPrice returns the price for the specified asset

func (*OpencxRPC) GetRegistrationString

func (cl *OpencxRPC) GetRegistrationString(args GetRegistrationStringArgs, reply *GetRegistrationStringReply) (err error)

GetRegistrationString returns a string to the client which is a valid string to sign to indicate they want their pubkey to be registered. This is like kinda weird but whatever

func (*OpencxRPC) Register

func (cl *OpencxRPC) Register(args RegisterArgs, reply *RegisterReply) (err error)

Register registers a pubkey into the db, verifies that the action was signed by that pubkey. A valid signature for the string "register" is considered a valid registration.

func (*OpencxRPC) SubmitOrder

func (cl *OpencxRPC) SubmitOrder(args SubmitOrderArgs, reply *SubmitOrderReply) (err error)

SubmitOrder submits an order to the order book or throws an error

func (*OpencxRPC) ViewOrderBook

func (cl *OpencxRPC) ViewOrderBook(args ViewOrderBookArgs, reply *ViewOrderBookReply) (err error)

ViewOrderBook handles the vieworderbook command

func (*OpencxRPC) Withdraw

func (cl *OpencxRPC) Withdraw(args WithdrawArgs, reply *WithdrawReply) (err error)

Withdraw is the RPC Interface for Withdraw

func (*OpencxRPC) WithdrawToLightningNode

func (cl *OpencxRPC) WithdrawToLightningNode(args WithdrawToLightningNodeArgs, reply *WithdrawToLightningNodeReply) (err error)

WithdrawToLightningNode creates a channel that pushes a certain amount to a lightning node through a lightning channel.

type OpencxRPCCaller

type OpencxRPCCaller struct {
	// contains filtered or unexported fields
}

OpencxRPCCaller is a listener for RPC commands

func CreateRPCForServer

func CreateRPCForServer(server *cxserver.OpencxServer) (rpc1 *OpencxRPCCaller, err error)

func (*OpencxRPCCaller) NoiseListen

func (rpc1 *OpencxRPCCaller) NoiseListen(privkey *koblitz.PrivateKey, host string, port uint16) (err error)

NoiseListen is a synchronous version of RPCListenAsync

func (*OpencxRPCCaller) NoiseListenAsync

func (rpc1 *OpencxRPCCaller) NoiseListenAsync(doneChan chan bool, errChan chan error, privkey *koblitz.PrivateKey, host string, port uint16)

NoiseListenAsync listens on socket host and port

func (*OpencxRPCCaller) RPCListen

func (rpc1 *OpencxRPCCaller) RPCListen(host string, port uint16) (err error)

RPCListen is a synchronous version of RPCListenAsync

func (*OpencxRPCCaller) RPCListenAsync

func (rpc1 *OpencxRPCCaller) RPCListenAsync(doneChan chan bool, errChan chan error, host string, port uint16)

RPCListenAsync listens on socket host and port

func (*OpencxRPCCaller) Stop

func (rpc1 *OpencxRPCCaller) Stop() (err error)

Stop closes the RPC listener and notifies those from WaitUntilDead

func (*OpencxRPCCaller) WaitUntilDead

func (rpc1 *OpencxRPCCaller) WaitUntilDead()

WaitUntilDead waits until the Stop() method is called

type OpencxRPCClient

type OpencxRPCClient struct {
	Conn *rpc.Client
}

OpencxRPCClient is a RPC client for the opencx server

func (*OpencxRPCClient) Call

func (cl *OpencxRPCClient) Call(serviceMethod string, args interface{}, reply interface{}) error

Call calls the servicemethod with name string, args args, and reply reply

func (*OpencxRPCClient) SetupConnection

func (cl *OpencxRPCClient) SetupConnection(server string, port uint16) (err error)

SetupConnection creates a new RPC client

type RegisterArgs

type RegisterArgs struct {
	Signature []byte
}

RegisterArgs holds the args for register

type RegisterReply

type RegisterReply struct {
}

RegisterReply holds the data for the register reply

type SubmitOrderArgs

type SubmitOrderArgs struct {
	Order *match.LimitOrder
	// Signature is a compact signature so we can do pubkey recovery
	Signature []byte
}

SubmitOrderArgs holds the args for the submitorder command

type SubmitOrderReply

type SubmitOrderReply struct {
	OrderID *match.OrderID
}

SubmitOrderReply holds the reply for the submitorder command

type ViewOrderBookArgs

type ViewOrderBookArgs struct {
	TradingPair *match.Pair
}

ViewOrderBookArgs holds the args for the vieworderbook command

type ViewOrderBookReply

type ViewOrderBookReply struct {
	Orderbook map[float64][]*match.LimitOrderIDPair
}

ViewOrderBookReply holds the reply for the vieworderbook command

type WithdrawArgs

type WithdrawArgs struct {
	Withdrawal *match.Withdrawal
	Signature  []byte
}

WithdrawArgs holds the args for Withdraw

type WithdrawReply

type WithdrawReply struct {
	Txid string
}

WithdrawReply holds the reply for Withdraw

type WithdrawToLightningNodeArgs

type WithdrawToLightningNodeArgs struct {
	Withdrawal *match.Withdrawal
	Signature  []byte
}

WithdrawToLightningNodeArgs holds the args for the withdrawtolightning RPC command

type WithdrawToLightningNodeReply

type WithdrawToLightningNodeReply struct {
	Txid string
}

WithdrawToLightningNodeReply holds the reply for the withdrawtolightning RPC command

Jump to

Keyboard shortcuts

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