Skip to content

Commit

Permalink
Merge pull request #15 from cryptomkt/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ppbustamante authored Jan 8, 2025
2 parents 7b8f9a7 + e35e4aa commit da93333
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 4 deletions.
17 changes: 15 additions & 2 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type Order struct {
Trades []TradeOfOrder `json:"trades"`
Contingency args.ContingencyType `json:"contingency_type"`
OrderListID string `json:"order_list_id"`
AveragePrice string `json:"price_average"`
}

// TradeOfOrder is the trade information of trades of an order
Expand Down Expand Up @@ -236,11 +237,19 @@ type CommitRisk struct {

// CryptoAddress is an crypto address
type CryptoAddress struct {
Currency string `json:"currency"`
Address string `json:"address"`
Currency string `json:"currency"`
NetworkCode string `json:"network_code"`
PaymentID string `json:"payment_id"`
PublicKey string `json:"publicKey"`
NetworkCode string `json:"network_code"`
}

// WhitelistAddress is an crypto address
type WhitelistAddress struct {
Address string `json:"address"`
Name string `json:"name"`
Currency string `json:"currency"`
Network string `json:"network"`
}

// PayoutCryptoAddress is for external crypto addresses
Expand Down Expand Up @@ -383,6 +392,10 @@ type FeeResponse struct {
NetworkCode string `json:"networkCode"`
}

type FeesHashResponse struct {
Hash string `json:"hash"`
}

type SubAccount struct {
ID string `json:"sub_account_id"`
Email string `json:"email"`
Expand Down
97 changes: 97 additions & 0 deletions rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,8 @@ func (client *Client) CreateSpotOrder(
// Quantity(string) // Order quantity
// StrictValidate(bool) // Price and quantity will be checked for incrementation within the symbol’s tick size and quantity step. See the symbol's TickSize and QuantityIncrement
// Price(string) // Required for OrderLimit, OrderStopLimit, or OrderTakeProfitLimit. Order price
//
// StopPrice(string) // Required if order type is OrderStopLimit', OrderStopMarket', OrderTakeProfitLimit, or OrderTakeProfitMarket. Order stop price
func (client *Client) ReplaceSpotOrder(
ctx context.Context,
arguments ...args.Argument,
Expand Down Expand Up @@ -1138,6 +1140,19 @@ func (client *Client) GetWalletBalanceOfCurrency(
return
}

// Gets the list of whitelisted addresses
//
// Requires the "Payment information" API key Access Right
//
// https://api.exchange.cryptomkt.com/#get-whitelisted-addresses
func (client *Client) getWhitelistedAddresses(
ctx context.Context,
) (result []models.WhitelistAddress, err error) {
err = client.privateGet(ctx, endpointWhitelistedAdresses, nil, &result)
return

}

// GetDepositCryptoAddresses gets a list of addresses with the current addresses of all currencies
//
// Requires the "Payment information" API key Access Right
Expand Down Expand Up @@ -1550,6 +1565,19 @@ func (client *Client) GetBulkEstimateWithdrawalFees(
return result, err
}

// GetWithdrawalFeesHash gets the hash of withdrawal fees
//
// Requires the "Payment information" API key Access Right
//
// https://api.exchange.cryptomkt.com/#get-withdrawal-fees-hash
func (client *Client) GetWithdrawalFeesHash(
ctx context.Context,
) (result string, err error) {
response := models.FeesHashResponse{}
err = client.privateGet(ctx, endpointWithdrawalFeesHash, nil, &response)
return response.Hash, err
}

// ConvertBetweenCurrencies Converts between currencies
//
// Successful response to the request does not necessarily mean the resulting transaction got executed immediately. It has to be processed first and may eventually be rolled back
Expand Down Expand Up @@ -1921,6 +1949,75 @@ func (client *Client) TransferFunds(
return response.Result, err
}

// TransferToSuperAccount creates and commits a transfer from a subaccount to its super account
//
// # Call is being sent by a subaccount
//
// Created but not committed transfer will reserve pending amount on the sender
// wallet affecting their ability to withdraw or transfer crypto to another
// account. Incomplete withdrawals affect subaccount transfers the same way
//
// Requires the "Withdraw cryptocurrencies" API key Access Right
//
// https://api.exchange.cryptomkt.com/#transfer-to-super-account
//
// Arguments:
//
// Amount(string) // amount to transfer
// Currency(string) // currency of transfer
func (client *Client) TransferToSuperAccount(
ctx context.Context,
arguments ...args.Argument,
) (result bool, err error) {
params, err := args.BuildParams(
arguments,
internal.ArgNameCurrency,
internal.ArgNameAmount,
)
if err != nil {
return
}
response := models.BooleanResponse{}
err = client.post(ctx, endpointSubAccountTransferToSuperAccount, params, &response)
return response.Result, err
}

// TransferToAnotherSubAccount creates and commits a transfer between the user (subaccount) and another
// subaccount.
//
// # Call is being sent by a subaccount
//
// Created but not committed transfer will reserve pending amount on the sender
// wallet affecting their ability to withdraw or transfer crypto to another
// account. Incomplete withdrawals affect subaccount transfers the same way
//
// Requires the "Withdraw cryptocurrencies" API key Access Right
//
// https://api.exchange.cryptomkt.com/#transfer-across-subaccounts
//
// Arguments:
//
// SubAccountID(string) // id of the sub-account to transfer to
// Amount(string) // amount to transfer
// Currency(string) // currency of transfer
func (client *Client) TransferToAnotherSubAccount(
ctx context.Context,
arguments ...args.Argument,
) (result bool, err error) {
params, err := args.BuildParams(
arguments,
internal.ArgNameSubAccountIDs,
internal.ArgNameCurrency,
internal.ArgNameAmount,
)
if err != nil {
return
}
response := models.BooleanResponse{}
err = client.post(ctx, endpointSubAccountTransferToAnotherSubAccount, params, &response)
return response.Result, err
}

// GetACLSettings get a list of withdrawal settings for all sub-accounts or for the specified sub-accounts and returns A list of ACL settings for subaccounts
//
// Requires the "Payment information" API key Access Right
Expand Down
4 changes: 2 additions & 2 deletions rest/client_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func TestGetPriceHistory(t *testing.T) {
if err = checkQuotationPriceHistory(&priceHistory); err != nil {
t.Fatal(err)
}
if len(priceHistory.History) != 3 {
t.Fatal("should have 3 history points")
if len(priceHistory.History) > 3 {
t.Fatal("should have at most 3 history points")
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions rest/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
endpointTradeHistory = "spot/history/trade"
// wallet management
endpointWalletBalance = "wallet/balance"
endpointWhitelistedAdresses = "wallet/crypto/address/white-list"
endpointCryptoAdress = "wallet/crypto/address"
endpointCryptoAdressRecentDeposit = "wallet/crypto/address/recent-deposit"
endpointCryptoAdressRecentWithdraw = "wallet/crypto/address/recent-withdraw"
Expand All @@ -35,6 +36,7 @@ const (
endpointEstimateWithdrawalFees = "wallet/crypto/fees/estimate"
endpointEstimateWithdrawalFee = "wallet/crypto/fee/estimate"
endpointBulkEstimateWithdrawalFees = "wallet/crypto/fee/estimate/bulk"
endpointWithdrawalFeesHash = "wallet/crypto/fee/withdraw/hash"
// endpointEstimateDepositFee = "wallet/crypto/fee/deposit/estimate"
// endpointBulkEstimateDepositFees = "wallet/crypto/fee/deposit/estimate/bulk"
endpointAmountLocks = "wallet/amount-locks"
Expand All @@ -43,6 +45,8 @@ const (
endpointFreezeSubAccount = "sub-account/freeze"
endpointActivateSubAccount = "sub-account/activate"
endpointSubAccountTransferFunds = "sub-account/transfer"
endpointSubAccountTransferToSuperAccount = "sub-account/transfer/sub-to-super"
endpointSubAccountTransferToAnotherSubAccount = "sub-account/transfer/sub-to-sub"
endpointSubaccountACLSettings = "sub-account/acl"
endpointSubaccountBalance = "sub-account/balance"
endpointSubaccountCryptoAddress = "sub-account/crypto/address"
Expand Down
1 change: 1 addition & 0 deletions websocket/trading_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func (client *SpotTradingClient) CancelAllSpotOrders(
// NewClientOrderID(string) // the new client order id for the modified order. must be unique within the trading day
// Quantity(string) // new order quantity
// Price(string) // new order price
// StopPrice(string) // Required if order type is OrderStopLimit', OrderStopMarket', OrderTakeProfitLimit, or OrderTakeProfitMarket. Order stop price
// StrictValidate(bool) // price and quantity will be checked for the incrementation with tick size and quantity step. See symbol's tick_size and quantity_increment
func (client *SpotTradingClient) ReplaceSpotOrder(
ctx context.Context,
Expand Down

0 comments on commit da93333

Please sign in to comment.