How to use GetRateLimiter method of client Package

Best Testkube code snippet using client.GetRateLimiter

http.go

Source:http.go Github

copy

Full Screen

1package coinbasepro2import "github.com/alpine-hodler/web/internal"3// * This is a generated file, do not edit4// Account will return data for a single account. Use this endpoint when you know the account_id. API key must belong to5// the same profile as the account.6//7// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccount8func (c *Client) Account(accountId string) (m *Account, _ error) {9 req, _ := internal.HTTPNewRequest("GET", "", nil)10 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),11 internal.HTTPWithEncoder(nil),12 internal.HTTPWithEndpoint(AccountPath),13 internal.HTTPWithParams(map[string]string{14 "account_id": accountId}),15 internal.HTTPWithRatelimiter(getRateLimiter(AccountRatelimiter, 5)),16 internal.HTTPWithRequest(req))17}18// AccountHolds will return the holds of an account that belong to the same profile as the API key. Holds are placed on19// an account for any active orders or pending withdraw requests. As an order is filled, the hold amount is updated. If20// an order is canceled, any remaining hold is removed. For withdrawals, the hold is removed after it is completed.21//22// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountholds23func (c *Client) AccountHolds(accountId string, opts *AccountHoldsOptions) (m []*AccountHold, _ error) {24 req, _ := internal.HTTPNewRequest("GET", "", opts)25 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),26 internal.HTTPWithEncoder(opts),27 internal.HTTPWithEndpoint(AccountHoldsPath),28 internal.HTTPWithParams(map[string]string{29 "account_id": accountId}),30 internal.HTTPWithRatelimiter(getRateLimiter(AccountHoldsRatelimiter, 5)),31 internal.HTTPWithRequest(req))32}33// AccountLedger returns ledger activity for an account. This includes anything that would affect the accounts balance -34// transfers, trades, fees, etc. This endpoint requires either the "view" or "trade" permission.35//36// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger37func (c *Client) AccountLedger(accountId string, opts *AccountLedgerOptions) (m []*AccountLedger, _ error) {38 req, _ := internal.HTTPNewRequest("GET", "", opts)39 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),40 internal.HTTPWithEncoder(opts),41 internal.HTTPWithEndpoint(AccountLedgerPath),42 internal.HTTPWithParams(map[string]string{43 "account_id": accountId}),44 internal.HTTPWithRatelimiter(getRateLimiter(AccountLedgerRatelimiter, 5)),45 internal.HTTPWithRequest(req))46}47// AccountTransfers returns past withdrawals and deposits for an account.48//49// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers50func (c *Client) AccountTransfers(accountId string, opts *AccountTransfersOptions) (m []*Transfer, _ error) {51 req, _ := internal.HTTPNewRequest("GET", "", opts)52 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),53 internal.HTTPWithEncoder(opts),54 internal.HTTPWithEndpoint(AccountTransfersPath),55 internal.HTTPWithParams(map[string]string{56 "account_id": accountId}),57 internal.HTTPWithRatelimiter(getRateLimiter(AccountTransfersRatelimiter, 5)),58 internal.HTTPWithRequest(req))59}60// Accounts will return a list of trading accounts from the profile of the API key.61//62// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts63func (c *Client) Accounts() (m []*Account, _ error) {64 req, _ := internal.HTTPNewRequest("GET", "", nil)65 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),66 internal.HTTPWithEncoder(nil),67 internal.HTTPWithEndpoint(AccountsPath),68 internal.HTTPWithParams(nil),69 internal.HTTPWithRatelimiter(getRateLimiter(AccountsRatelimiter, 5)),70 internal.HTTPWithRequest(req))71}72// Book will return a list of open orders for a product. The amount of detail shown can be customized with the level73// parameter.74//75// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductbook76func (c *Client) Book(productId string, opts *BookOptions) (m *Book, _ error) {77 req, _ := internal.HTTPNewRequest("GET", "", opts)78 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),79 internal.HTTPWithEncoder(opts),80 internal.HTTPWithEndpoint(BookPath),81 internal.HTTPWithParams(map[string]string{82 "product_id": productId}),83 internal.HTTPWithRatelimiter(getRateLimiter(BookRatelimiter, 5)),84 internal.HTTPWithRequest(req))85}86// CancelOpenOrders will try with best effort to cancel all open orders. This may require you to make the request87// multiple times until all of the open orders are deleted.88//89// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorders90func (c *Client) CancelOpenOrders(opts *CancelOpenOrdersOptions) (m []*string, _ error) {91 req, _ := internal.HTTPNewRequest("DELETE", "", opts)92 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),93 internal.HTTPWithEncoder(opts),94 internal.HTTPWithEndpoint(CancelOpenOrdersPath),95 internal.HTTPWithParams(nil),96 internal.HTTPWithRatelimiter(getRateLimiter(CancelOpenOrdersRatelimiter, 5)),97 internal.HTTPWithRequest(req))98}99// CancelOrder will cancel a single open order by order id.100//101// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorder102func (c *Client) CancelOrder(orderId string) (m string, _ error) {103 req, _ := internal.HTTPNewRequest("DELETE", "", nil)104 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),105 internal.HTTPWithEncoder(nil),106 internal.HTTPWithEndpoint(CancelOrderPath),107 internal.HTTPWithParams(map[string]string{108 "order_id": orderId}),109 internal.HTTPWithRatelimiter(getRateLimiter(CancelOrderRatelimiter, 5)),110 internal.HTTPWithRequest(req))111}112// Candles will return historic rates for a product.113//114// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles115func (c *Client) Candles(productId string, opts *CandlesOptions) (m *Candles, _ error) {116 req, _ := internal.HTTPNewRequest("GET", "", opts)117 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),118 internal.HTTPWithEncoder(opts),119 internal.HTTPWithEndpoint(CandlesPath),120 internal.HTTPWithParams(map[string]string{121 "product_id": productId}),122 internal.HTTPWithRatelimiter(getRateLimiter(CandlesRatelimiter, 5)),123 internal.HTTPWithRequest(req))124}125// CoinbaseAccountDeposit funds from a www.coinbase.com wallet to the specified profile_id.126//127// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postdepositcoinbaseaccount128func (c *Client) CoinbaseAccountDeposit(opts *CoinbaseAccountDepositOptions) (m *Deposit, _ error) {129 req, _ := internal.HTTPNewRequest("POST", "", opts)130 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),131 internal.HTTPWithEncoder(nil),132 internal.HTTPWithEndpoint(CoinbaseAccountDepositPath),133 internal.HTTPWithParams(nil),134 internal.HTTPWithRatelimiter(getRateLimiter(CoinbaseAccountDepositRatelimiter, 5)),135 internal.HTTPWithRequest(req))136}137// AccountWithdraws funds from the specified profile_id to a www.coinbase.com wallet. Withdraw funds to a coinbase138// account. You can move funds between your Coinbase accounts and your Coinbase Exchange trading accounts within your139// daily limits. Moving funds between Coinbase and Coinbase Exchange is instant and free. See the Coinbase Accounts140// section for retrieving your Coinbase accounts. This endpoint requires the "transfer" permission.141//142// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawcoinbaseaccount143func (c *Client) CoinbaseAccountWithdrawal(opts *CoinbaseAccountWithdrawalOptions) (m *Withdrawal, _ error) {144 req, _ := internal.HTTPNewRequest("POST", "", opts)145 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),146 internal.HTTPWithEncoder(nil),147 internal.HTTPWithEndpoint(CoinbaseAccountWithdrawalPath),148 internal.HTTPWithParams(nil),149 internal.HTTPWithRatelimiter(getRateLimiter(CoinbaseAccountWithdrawalRatelimiter, 5)),150 internal.HTTPWithRequest(req))151}152// ConvertCurrency converts funds from from currency to to currency. Funds are converted on the from account in the153// profile_id profile. This endpoint requires the "trade" permission. A successful conversion will be assigned a154// conversion id. The corresponding ledger entries for a conversion will reference this conversion id155//156// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postconversion157func (c *Client) ConvertCurrency(opts *ConvertCurrencyOptions) (m *CurrencyConversion, _ error) {158 req, _ := internal.HTTPNewRequest("POST", "", opts)159 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),160 internal.HTTPWithEncoder(nil),161 internal.HTTPWithEndpoint(ConvertCurrencyPath),162 internal.HTTPWithParams(nil),163 internal.HTTPWithRatelimiter(getRateLimiter(ConvertCurrencyRatelimiter, 5)),164 internal.HTTPWithRequest(req))165}166// CreateOrder will create a new an order. You can place two types of orders: limit and market. Orders can only be167// placed if your account has sufficient funds. Once an order is placed, your account funds will be put on hold for the168// duration of the order. How much and which funds are put on hold depends on the order type and parameters specified.169//170// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postorders171func (c *Client) CreateOrder(opts *CreateOrderOptions) (m *CreateOrder, _ error) {172 req, _ := internal.HTTPNewRequest("POST", "", opts)173 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),174 internal.HTTPWithEncoder(nil),175 internal.HTTPWithEndpoint(CreateOrderPath),176 internal.HTTPWithParams(nil),177 internal.HTTPWithRatelimiter(getRateLimiter(CreateOrderRatelimiter, 5)),178 internal.HTTPWithRequest(req))179}180// CreateProfile will create a new profile. Will fail if no name is provided or if user already has max number of181// profiles.182//183// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postprofile184func (c *Client) CreateProfile(opts *CreateProfileOptions) (m *Profile, _ error) {185 req, _ := internal.HTTPNewRequest("POST", "", opts)186 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),187 internal.HTTPWithEncoder(nil),188 internal.HTTPWithEndpoint(CreateProfilePath),189 internal.HTTPWithParams(nil),190 internal.HTTPWithRatelimiter(getRateLimiter(CreateProfileRatelimiter, 5)),191 internal.HTTPWithRequest(req))192}193// CreateProfileTransfer will transfer an amount of currency from one profile to another. This endpoint requires the194// "transfer" permission.195//196// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postprofiletransfer197func (c *Client) CreateProfileTransfer(opts *CreateProfileTransferOptions) error {198 req, _ := internal.HTTPNewRequest("POST", "", opts)199 return internal.HTTPFetch(nil, internal.HTTPWithClient(c.Client),200 internal.HTTPWithEncoder(nil),201 internal.HTTPWithEndpoint(CreateProfileTransferPath),202 internal.HTTPWithParams(nil),203 internal.HTTPWithRatelimiter(getRateLimiter(CreateProfileTransferRatelimiter, 5)),204 internal.HTTPWithRequest(req))205}206// CreateReport generates a report. Reports are either for past account history or past fills on either all accounts or207// one product's account.208//209// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postreports210func (c *Client) CreateReport(opts *CreateReportOptions) (m *CreateReport, _ error) {211 req, _ := internal.HTTPNewRequest("POST", "", opts)212 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),213 internal.HTTPWithEncoder(nil),214 internal.HTTPWithEndpoint(CreateReportPath),215 internal.HTTPWithParams(nil),216 internal.HTTPWithRatelimiter(getRateLimiter(CreateReportRatelimiter, 5)),217 internal.HTTPWithRequest(req))218}219// CryptoWithdrawal funds from the specified profile_id to an external crypto address. This endpoint requires the220// "transfer" permission. API key must belong to default profile.221//222// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawcrypto223func (c *Client) CryptoWithdrawal(opts *CryptoWithdrawalOptions) (m *Withdrawal, _ error) {224 req, _ := internal.HTTPNewRequest("POST", "", opts)225 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),226 internal.HTTPWithEncoder(nil),227 internal.HTTPWithEndpoint(CryptoWithdrawalPath),228 internal.HTTPWithParams(nil),229 internal.HTTPWithRatelimiter(getRateLimiter(CryptoWithdrawalRatelimiter, 5)),230 internal.HTTPWithRequest(req))231}232// Currencies returns a list of all known currencies. Note: Not all currencies may be currently in use for trading.233//234// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcurrencies235func (c *Client) Currencies() (m []*Currency, _ error) {236 req, _ := internal.HTTPNewRequest("GET", "", nil)237 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),238 internal.HTTPWithEncoder(nil),239 internal.HTTPWithEndpoint(CurrenciesPath),240 internal.HTTPWithParams(nil),241 internal.HTTPWithRatelimiter(getRateLimiter(CurrenciesRatelimiter, 5)),242 internal.HTTPWithRequest(req))243}244// Currency returns a single currency by id.245//246// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcurrency247func (c *Client) Currency(currencyId string) (m *Currency, _ error) {248 req, _ := internal.HTTPNewRequest("GET", "", nil)249 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),250 internal.HTTPWithEncoder(nil),251 internal.HTTPWithEndpoint(CurrencyPath),252 internal.HTTPWithParams(map[string]string{253 "currency_id": currencyId}),254 internal.HTTPWithRatelimiter(getRateLimiter(CurrencyRatelimiter, 5)),255 internal.HTTPWithRequest(req))256}257// CurrencyConversion returns the currency conversion by conversion id (i.e. USD -> USDC).258//259// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getconversion260func (c *Client) CurrencyConversion(conversionId string, opts *CurrencyConversionOptions) (m *CurrencyConversion, _ error) {261 req, _ := internal.HTTPNewRequest("GET", "", opts)262 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),263 internal.HTTPWithEncoder(opts),264 internal.HTTPWithEndpoint(CurrencyConversionPath),265 internal.HTTPWithParams(map[string]string{266 "conversion_id": conversionId}),267 internal.HTTPWithRatelimiter(getRateLimiter(CurrencyConversionRatelimiter, 5)),268 internal.HTTPWithRequest(req))269}270// DeleteProfile deletes the profile specified by profile_id and transfers all funds to the profile specified by to.271// Fails if there are any open orders on the profile to be deleted.272//273// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_putprofiledeactivate274func (c *Client) DeleteProfile(profileId string, opts *DeleteProfileOptions) error {275 req, _ := internal.HTTPNewRequest("PUT", "", opts)276 return internal.HTTPFetch(nil, internal.HTTPWithClient(c.Client),277 internal.HTTPWithEncoder(opts),278 internal.HTTPWithEndpoint(DeleteProfilePath),279 internal.HTTPWithParams(map[string]string{280 "profile_id": profileId}),281 internal.HTTPWithRatelimiter(getRateLimiter(DeleteProfileRatelimiter, 5)),282 internal.HTTPWithRequest(req))283}284// ExchangeLimits returns exchange limits information for a single user.285//286// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getuserexchangelimits287func (c *Client) ExchangeLimits(userId string) (m *ExchangeLimits, _ error) {288 req, _ := internal.HTTPNewRequest("GET", "", nil)289 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),290 internal.HTTPWithEncoder(nil),291 internal.HTTPWithEndpoint(ExchangeLimitsPath),292 internal.HTTPWithParams(map[string]string{293 "user_id": userId}),294 internal.HTTPWithRatelimiter(getRateLimiter(ExchangeLimitsRatelimiter, 5)),295 internal.HTTPWithRequest(req))296}297// Fees returns fees rates and 30 days trailing volume.298//299// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfees300func (c *Client) Fees() (m *Fees, _ error) {301 req, _ := internal.HTTPNewRequest("GET", "", nil)302 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),303 internal.HTTPWithEncoder(nil),304 internal.HTTPWithEndpoint(FeesPath),305 internal.HTTPWithParams(nil),306 internal.HTTPWithRatelimiter(getRateLimiter(FeesRatelimiter, 5)),307 internal.HTTPWithRequest(req))308}309// Fills returns a list of fills. A fill is a partial or complete match on a specific order.310//311// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfills312func (c *Client) Fills(opts *FillsOptions) (m []*Fill, _ error) {313 req, _ := internal.HTTPNewRequest("GET", "", opts)314 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),315 internal.HTTPWithEncoder(opts),316 internal.HTTPWithEndpoint(FillsPath),317 internal.HTTPWithParams(nil),318 internal.HTTPWithRatelimiter(getRateLimiter(FillsRatelimiter, 5)),319 internal.HTTPWithRequest(req))320}321// GenerateCryptoAddress will create a one-time crypto address for depositing crypto, using a wallet account id. This322// endpoint requires the "transfer" permission. API key must belong to default profile.323//324// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses325func (c *Client) GenerateCryptoAddress(accountId string) (m *CryptoAddress, _ error) {326 req, _ := internal.HTTPNewRequest("POST", "", nil)327 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),328 internal.HTTPWithEncoder(nil),329 internal.HTTPWithEndpoint(GenerateCryptoAddressPath),330 internal.HTTPWithParams(map[string]string{331 "account_id": accountId}),332 internal.HTTPWithRatelimiter(getRateLimiter(GenerateCryptoAddressRatelimiter, 5)),333 internal.HTTPWithRequest(req))334}335// Order returns a single order by id.336//337// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorder338func (c *Client) Order(orderId string) (m *Order, _ error) {339 req, _ := internal.HTTPNewRequest("GET", "", nil)340 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),341 internal.HTTPWithEncoder(nil),342 internal.HTTPWithEndpoint(OrderPath),343 internal.HTTPWithParams(map[string]string{344 "order_id": orderId}),345 internal.HTTPWithRatelimiter(getRateLimiter(OrderRatelimiter, 5)),346 internal.HTTPWithRequest(req))347}348// Orders will return your current open orders. Only open or un-settled orders are returned by default. As soon as an349// order is no longer open and settled, it will no longer appear in the default request. Open orders may change state350// between the request and the response depending on market conditions.351//352// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders353func (c *Client) Orders(opts *OrdersOptions) (m []*Order, _ error) {354 req, _ := internal.HTTPNewRequest("GET", "", opts)355 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),356 internal.HTTPWithEncoder(opts),357 internal.HTTPWithEndpoint(OrdersPath),358 internal.HTTPWithParams(nil),359 internal.HTTPWithRatelimiter(getRateLimiter(OrdersRatelimiter, 5)),360 internal.HTTPWithRequest(req))361}362// PaymentMethodDeposit will fund from a linked external payment method to the specified profile_id.363//364// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postdepositpaymentmethod365func (c *Client) PaymentMethodDeposit(opts *PaymentMethodDepositOptions) (m *Deposit, _ error) {366 req, _ := internal.HTTPNewRequest("POST", "", opts)367 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),368 internal.HTTPWithEncoder(nil),369 internal.HTTPWithEndpoint(PaymentMethodDepositPath),370 internal.HTTPWithParams(nil),371 internal.HTTPWithRatelimiter(getRateLimiter(PaymentMethodDepositRatelimiter, 5)),372 internal.HTTPWithRequest(req))373}374// PaymentMethodWithdrawal will fund from the specified profile_id to a linked external payment method. This endpoint375// requires the "transfer" permission. API key is restricted to the default profile.376//377// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawpaymentmethod378func (c *Client) PaymentMethodWithdrawal(opts *PaymentMethodWithdrawalOptions) (m *Withdrawal, _ error) {379 req, _ := internal.HTTPNewRequest("POST", "", opts)380 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),381 internal.HTTPWithEncoder(nil),382 internal.HTTPWithEndpoint(PaymentMethodWithdrawalPath),383 internal.HTTPWithParams(nil),384 internal.HTTPWithRatelimiter(getRateLimiter(PaymentMethodWithdrawalRatelimiter, 5)),385 internal.HTTPWithRequest(req))386}387// PaymentMethods returns a list of the user's linked payment methods.388//389// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getpaymentmethods390func (c *Client) PaymentMethods() (m []*PaymentMethod, _ error) {391 req, _ := internal.HTTPNewRequest("GET", "", nil)392 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),393 internal.HTTPWithEncoder(nil),394 internal.HTTPWithEndpoint(PaymentMethodsPath),395 internal.HTTPWithParams(nil),396 internal.HTTPWithRatelimiter(getRateLimiter(PaymentMethodsRatelimiter, 5)),397 internal.HTTPWithRequest(req))398}399// Product will return information on a single product.400//401// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproduct402func (c *Client) Product(productId string) (m *Product, _ error) {403 req, _ := internal.HTTPNewRequest("GET", "", nil)404 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),405 internal.HTTPWithEncoder(nil),406 internal.HTTPWithEndpoint(ProductPath),407 internal.HTTPWithParams(map[string]string{408 "product_id": productId}),409 internal.HTTPWithRatelimiter(getRateLimiter(ProductRatelimiter, 5)),410 internal.HTTPWithRequest(req))411}412// ProductStats will return 30day and 24hour stats for a product.413//414// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductstats415func (c *Client) ProductStats(productId string) (m *ProductStats, _ error) {416 req, _ := internal.HTTPNewRequest("GET", "", nil)417 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),418 internal.HTTPWithEncoder(nil),419 internal.HTTPWithEndpoint(ProductStatsPath),420 internal.HTTPWithParams(map[string]string{421 "product_id": productId}),422 internal.HTTPWithRatelimiter(getRateLimiter(ProductStatsRatelimiter, 5)),423 internal.HTTPWithRequest(req))424}425// ProductTicker will return snapshot information about the last trade (tick), best bid/ask and 24h volume.426//427// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker428func (c *Client) ProductTicker(productId string) (m *ProductTicker, _ error) {429 req, _ := internal.HTTPNewRequest("GET", "", nil)430 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),431 internal.HTTPWithEncoder(nil),432 internal.HTTPWithEndpoint(ProductTickerPath),433 internal.HTTPWithParams(map[string]string{434 "product_id": productId}),435 internal.HTTPWithRatelimiter(getRateLimiter(ProductTickerRatelimiter, 5)),436 internal.HTTPWithRequest(req))437}438// Products will return a list of available currency pairs for trading.439//440// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts441func (c *Client) Products(opts *ProductsOptions) (m []*Product, _ error) {442 req, _ := internal.HTTPNewRequest("GET", "", opts)443 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),444 internal.HTTPWithEncoder(opts),445 internal.HTTPWithEndpoint(ProductsPath),446 internal.HTTPWithParams(nil),447 internal.HTTPWithRatelimiter(getRateLimiter(ProductsRatelimiter, 5)),448 internal.HTTPWithRequest(req))449}450// Profile returns information for a single profile. Use this endpoint when you know the profile_id. This endpoint451// requires the "view" permission and is accessible by any profile's API key.452//453// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getprofile454func (c *Client) Profile(profileId string, opts *ProfileOptions) (m *Profile, _ error) {455 req, _ := internal.HTTPNewRequest("GET", "", opts)456 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),457 internal.HTTPWithEncoder(opts),458 internal.HTTPWithEndpoint(ProfilePath),459 internal.HTTPWithParams(map[string]string{460 "profile_id": profileId}),461 internal.HTTPWithRatelimiter(getRateLimiter(ProfileRatelimiter, 5)),462 internal.HTTPWithRequest(req))463}464// Profiles returns a list of all of the current user's profiles.465//466// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getprofiles467func (c *Client) Profiles(opts *ProfilesOptions) (m []*Profile, _ error) {468 req, _ := internal.HTTPNewRequest("GET", "", opts)469 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),470 internal.HTTPWithEncoder(opts),471 internal.HTTPWithEndpoint(ProfilesPath),472 internal.HTTPWithParams(nil),473 internal.HTTPWithRatelimiter(getRateLimiter(ProfilesRatelimiter, 5)),474 internal.HTTPWithRequest(req))475}476// RenameProfile will rename a profile. Names 'default' and 'margin' are reserved.477//478// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_putprofile479func (c *Client) RenameProfile(profileId string, opts *RenameProfileOptions) (m *Profile, _ error) {480 req, _ := internal.HTTPNewRequest("PUT", "", opts)481 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),482 internal.HTTPWithEncoder(opts),483 internal.HTTPWithEndpoint(RenameProfilePath),484 internal.HTTPWithParams(map[string]string{485 "profile_id": profileId}),486 internal.HTTPWithRatelimiter(getRateLimiter(RenameProfileRatelimiter, 5)),487 internal.HTTPWithRequest(req))488}489// Report will return a specific report by report_id.490//491// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getreport492func (c *Client) Report(reportId string) (m *Report, _ error) {493 req, _ := internal.HTTPNewRequest("GET", "", nil)494 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),495 internal.HTTPWithEncoder(nil),496 internal.HTTPWithEndpoint(ReportPath),497 internal.HTTPWithParams(map[string]string{498 "report_id": reportId}),499 internal.HTTPWithRatelimiter(getRateLimiter(ReportRatelimiter, 5)),500 internal.HTTPWithRequest(req))501}502// Reports returns a list of past fills/account reports.503//504// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getreports505func (c *Client) Reports(opts *ReportsOptions) (m []*Report, _ error) {506 req, _ := internal.HTTPNewRequest("GET", "", opts)507 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),508 internal.HTTPWithEncoder(opts),509 internal.HTTPWithEndpoint(ReportsPath),510 internal.HTTPWithParams(nil),511 internal.HTTPWithRatelimiter(getRateLimiter(ReportsRatelimiter, 5)),512 internal.HTTPWithRequest(req))513}514// SignedPrices returns cryptographically signed prices ready to be posted on-chain using Compound's Open Oracle smart515// contract.516//517// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcoinbasepriceoracle518func (c *Client) SignedPrices() (m *Oracle, _ error) {519 req, _ := internal.HTTPNewRequest("GET", "", nil)520 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),521 internal.HTTPWithEncoder(nil),522 internal.HTTPWithEndpoint(SignedPricesPath),523 internal.HTTPWithParams(nil),524 internal.HTTPWithRatelimiter(getRateLimiter(SignedPricesRatelimiter, 5)),525 internal.HTTPWithRequest(req))526}527// Trades retruns a list the latest trades for a product.528//529// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducttrades530func (c *Client) Trades(productId string, opts *TradesOptions) (m []*Trade, _ error) {531 req, _ := internal.HTTPNewRequest("GET", "", opts)532 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),533 internal.HTTPWithEncoder(opts),534 internal.HTTPWithEndpoint(TradesPath),535 internal.HTTPWithParams(map[string]string{536 "product_id": productId}),537 internal.HTTPWithRatelimiter(getRateLimiter(TradesRatelimiter, 5)),538 internal.HTTPWithRequest(req))539}540// AccountTransfer returns information on a single transfer.541//542// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfer543func (c *Client) Transfer(transferId string) (m *Transfer, _ error) {544 req, _ := internal.HTTPNewRequest("GET", "", nil)545 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),546 internal.HTTPWithEncoder(nil),547 internal.HTTPWithEndpoint(TransferPath),548 internal.HTTPWithParams(map[string]string{549 "transfer_id": transferId}),550 internal.HTTPWithRatelimiter(getRateLimiter(TransferRatelimiter, 5)),551 internal.HTTPWithRequest(req))552}553// Transfers is a list of in-progress and completed transfers of funds in/out of any of the user's accounts.554//555// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers556func (c *Client) Transfers() (m []*Transfer, _ error) {557 req, _ := internal.HTTPNewRequest("GET", "", nil)558 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),559 internal.HTTPWithEncoder(nil),560 internal.HTTPWithEndpoint(TransfersPath),561 internal.HTTPWithParams(nil),562 internal.HTTPWithRatelimiter(getRateLimiter(TransfersRatelimiter, 5)),563 internal.HTTPWithRequest(req))564}565// Wallets will return all the user's available Coinbase wallets (These are the wallets/accounts that are used for566// buying and selling on www.coinbase.com)567//568// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcoinbaseaccounts569func (c *Client) Wallets() (m []*Wallet, _ error) {570 req, _ := internal.HTTPNewRequest("GET", "", nil)571 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),572 internal.HTTPWithEncoder(nil),573 internal.HTTPWithEndpoint(WalletsPath),574 internal.HTTPWithParams(nil),575 internal.HTTPWithRatelimiter(getRateLimiter(WalletsRatelimiter, 5)),576 internal.HTTPWithRequest(req))577}578// WithdrawalFeeEstimate will return the fee estimate for the crypto withdrawal to crypto address579//580// source: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getwithdrawfeeestimate581func (c *Client) WithdrawalFeeEstimate(opts *WithdrawalFeeEstimateOptions) (m *WithdrawalFeeEstimate, _ error) {582 req, _ := internal.HTTPNewRequest("GET", "", opts)583 return m, internal.HTTPFetch(&m, internal.HTTPWithClient(c.Client),584 internal.HTTPWithEncoder(opts),585 internal.HTTPWithEndpoint(WithdrawalFeeEstimatePath),586 internal.HTTPWithParams(nil),587 internal.HTTPWithRatelimiter(getRateLimiter(WithdrawalFeeEstimateRatelimiter, 5)),588 internal.HTTPWithRequest(req))589}...

Full Screen

Full Screen

visibilitySamplingClient.go

Source:visibilitySamplingClient.go Github

copy

Full Screen

1// Copyright (c) 2017 Uber Technologies, Inc.2//3// Permission is hereby granted, free of charge, to any person obtaining a copy4// of this software and associated documentation files (the "Software"), to deal5// in the Software without restriction, including without limitation the rights6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell7// copies of the Software, and to permit persons to whom the Software is8// furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN19// THE SOFTWARE.20package persistence21import (22 "sync"23 workflow "github.com/uber/cadence/.gen/go/shared"24 "github.com/uber/cadence/common/clock"25 "github.com/uber/cadence/common/log"26 "github.com/uber/cadence/common/log/tag"27 "github.com/uber/cadence/common/metrics"28 "github.com/uber/cadence/common/service/config"29 "github.com/uber/cadence/common/tokenbucket"30)31const (32 // To sample visibility request, open has only 1 bucket, closed has 233 numOfPriorityForOpen = 134 numOfPriorityForClosed = 235 numOfPriorityForList = 136)37type visibilitySamplingClient struct {38 rateLimitersForOpen *domainToBucketMap39 rateLimitersForClosed *domainToBucketMap40 rateLimitersForList *domainToBucketMap41 persistence VisibilityManager42 config *config.VisibilityConfig43 metricClient metrics.Client44 logger log.Logger45}46var _ VisibilityManager = (*visibilitySamplingClient)(nil)47// NewVisibilitySamplingClient creates a client to manage visibility with sampling48func NewVisibilitySamplingClient(persistence VisibilityManager, config *config.VisibilityConfig, metricClient metrics.Client, logger log.Logger) VisibilityManager {49 return &visibilitySamplingClient{50 persistence: persistence,51 rateLimitersForOpen: newDomainToBucketMap(),52 rateLimitersForClosed: newDomainToBucketMap(),53 rateLimitersForList: newDomainToBucketMap(),54 config: config,55 metricClient: metricClient,56 logger: logger,57 }58}59type domainToBucketMap struct {60 sync.RWMutex61 mappings map[string]tokenbucket.PriorityTokenBucket62}63func newDomainToBucketMap() *domainToBucketMap {64 return &domainToBucketMap{65 mappings: make(map[string]tokenbucket.PriorityTokenBucket),66 }67}68func (m *domainToBucketMap) getRateLimiter(domain string, numOfPriority, qps int) tokenbucket.PriorityTokenBucket {69 m.RLock()70 rateLimiter, exist := m.mappings[domain]71 m.RUnlock()72 if exist {73 return rateLimiter74 }75 m.Lock()76 if rateLimiter, ok := m.mappings[domain]; ok { // read again to ensure no duplicate create77 m.Unlock()78 return rateLimiter79 }80 rateLimiter = tokenbucket.NewFullPriorityTokenBucket(numOfPriority, qps, clock.NewRealTimeSource())81 m.mappings[domain] = rateLimiter82 m.Unlock()83 return rateLimiter84}85func (p *visibilitySamplingClient) RecordWorkflowExecutionStarted(request *RecordWorkflowExecutionStartedRequest) error {86 domain := request.Domain87 domainID := request.DomainUUID88 rateLimiter := p.rateLimitersForOpen.getRateLimiter(domain, numOfPriorityForOpen, p.config.VisibilityOpenMaxQPS(domain))89 if ok, _ := rateLimiter.GetToken(0, 1); ok {90 return p.persistence.RecordWorkflowExecutionStarted(request)91 }92 p.logger.Info("Request for open workflow is sampled",93 tag.WorkflowDomainID(domainID),94 tag.WorkflowDomainName(domain),95 tag.WorkflowType(request.WorkflowTypeName),96 tag.WorkflowID(request.Execution.GetWorkflowId()),97 tag.WorkflowRunID(request.Execution.GetRunId()),98 )99 p.metricClient.IncCounter(metrics.PersistenceRecordWorkflowExecutionStartedScope, metrics.PersistenceSampledCounter)100 return nil101}102func (p *visibilitySamplingClient) RecordWorkflowExecutionClosed(request *RecordWorkflowExecutionClosedRequest) error {103 domain := request.Domain104 domainID := request.DomainUUID105 priority := getRequestPriority(request)106 rateLimiter := p.rateLimitersForClosed.getRateLimiter(domain, numOfPriorityForClosed, p.config.VisibilityClosedMaxQPS(domain))107 if ok, _ := rateLimiter.GetToken(priority, 1); ok {108 return p.persistence.RecordWorkflowExecutionClosed(request)109 }110 p.logger.Info("Request for closed workflow is sampled",111 tag.WorkflowDomainID(domainID),112 tag.WorkflowDomainName(domain),113 tag.WorkflowType(request.WorkflowTypeName),114 tag.WorkflowID(request.Execution.GetWorkflowId()),115 tag.WorkflowRunID(request.Execution.GetRunId()),116 )117 p.metricClient.IncCounter(metrics.PersistenceRecordWorkflowExecutionClosedScope, metrics.PersistenceSampledCounter)118 return nil119}120func (p *visibilitySamplingClient) UpsertWorkflowExecution(request *UpsertWorkflowExecutionRequest) error {121 domain := request.Domain122 domainID := request.DomainUUID123 rateLimiter := p.rateLimitersForClosed.getRateLimiter(domain, numOfPriorityForClosed, p.config.VisibilityClosedMaxQPS(domain))124 if ok, _ := rateLimiter.GetToken(0, 1); ok {125 return p.persistence.UpsertWorkflowExecution(request)126 }127 p.logger.Info("Request for upsert workflow is sampled",128 tag.WorkflowDomainID(domainID),129 tag.WorkflowDomainName(domain),130 tag.WorkflowType(request.WorkflowTypeName),131 tag.WorkflowID(request.Execution.GetWorkflowId()),132 tag.WorkflowRunID(request.Execution.GetRunId()),133 )134 p.metricClient.IncCounter(metrics.PersistenceUpsertWorkflowExecutionScope, metrics.PersistenceSampledCounter)135 return nil136}137func (p *visibilitySamplingClient) ListOpenWorkflowExecutions(request *ListWorkflowExecutionsRequest) (*ListWorkflowExecutionsResponse, error) {138 domain := request.Domain139 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))140 if ok, _ := rateLimiter.GetToken(0, 1); !ok {141 return nil, ErrPersistenceLimitExceededForList142 }143 return p.persistence.ListOpenWorkflowExecutions(request)144}145func (p *visibilitySamplingClient) ListClosedWorkflowExecutions(request *ListWorkflowExecutionsRequest) (*ListWorkflowExecutionsResponse, error) {146 domain := request.Domain147 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))148 if ok, _ := rateLimiter.GetToken(0, 1); !ok {149 return nil, ErrPersistenceLimitExceededForList150 }151 return p.persistence.ListClosedWorkflowExecutions(request)152}153func (p *visibilitySamplingClient) ListOpenWorkflowExecutionsByType(request *ListWorkflowExecutionsByTypeRequest) (*ListWorkflowExecutionsResponse, error) {154 domain := request.Domain155 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))156 if ok, _ := rateLimiter.GetToken(0, 1); !ok {157 return nil, ErrPersistenceLimitExceededForList158 }159 return p.persistence.ListOpenWorkflowExecutionsByType(request)160}161func (p *visibilitySamplingClient) ListClosedWorkflowExecutionsByType(request *ListWorkflowExecutionsByTypeRequest) (*ListWorkflowExecutionsResponse, error) {162 domain := request.Domain163 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))164 if ok, _ := rateLimiter.GetToken(0, 1); !ok {165 return nil, ErrPersistenceLimitExceededForList166 }167 return p.persistence.ListClosedWorkflowExecutionsByType(request)168}169func (p *visibilitySamplingClient) ListOpenWorkflowExecutionsByWorkflowID(request *ListWorkflowExecutionsByWorkflowIDRequest) (*ListWorkflowExecutionsResponse, error) {170 domain := request.Domain171 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))172 if ok, _ := rateLimiter.GetToken(0, 1); !ok {173 return nil, ErrPersistenceLimitExceededForList174 }175 return p.persistence.ListOpenWorkflowExecutionsByWorkflowID(request)176}177func (p *visibilitySamplingClient) ListClosedWorkflowExecutionsByWorkflowID(request *ListWorkflowExecutionsByWorkflowIDRequest) (*ListWorkflowExecutionsResponse, error) {178 domain := request.Domain179 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))180 if ok, _ := rateLimiter.GetToken(0, 1); !ok {181 return nil, ErrPersistenceLimitExceededForList182 }183 return p.persistence.ListClosedWorkflowExecutionsByWorkflowID(request)184}185func (p *visibilitySamplingClient) ListClosedWorkflowExecutionsByStatus(request *ListClosedWorkflowExecutionsByStatusRequest) (*ListWorkflowExecutionsResponse, error) {186 domain := request.Domain187 rateLimiter := p.rateLimitersForList.getRateLimiter(domain, numOfPriorityForList, p.config.VisibilityListMaxQPS(domain))188 if ok, _ := rateLimiter.GetToken(0, 1); !ok {189 return nil, ErrPersistenceLimitExceededForList190 }191 return p.persistence.ListClosedWorkflowExecutionsByStatus(request)192}193func (p *visibilitySamplingClient) GetClosedWorkflowExecution(request *GetClosedWorkflowExecutionRequest) (*GetClosedWorkflowExecutionResponse, error) {194 return p.persistence.GetClosedWorkflowExecution(request)195}196func (p *visibilitySamplingClient) DeleteWorkflowExecution(request *VisibilityDeleteWorkflowExecutionRequest) error {197 return p.persistence.DeleteWorkflowExecution(request)198}199func (p *visibilitySamplingClient) ListWorkflowExecutions(request *ListWorkflowExecutionsRequestV2) (*ListWorkflowExecutionsResponse, error) {200 return p.persistence.ListWorkflowExecutions(request)201}202func (p *visibilitySamplingClient) ScanWorkflowExecutions(request *ListWorkflowExecutionsRequestV2) (*ListWorkflowExecutionsResponse, error) {203 return p.persistence.ScanWorkflowExecutions(request)204}205func (p *visibilitySamplingClient) CountWorkflowExecutions(request *CountWorkflowExecutionsRequest) (*CountWorkflowExecutionsResponse, error) {206 return p.persistence.CountWorkflowExecutions(request)207}208func (p *visibilitySamplingClient) Close() {209 p.persistence.Close()210}211func (p *visibilitySamplingClient) GetName() string {212 return p.persistence.GetName()213}214func getRequestPriority(request *RecordWorkflowExecutionClosedRequest) int {215 priority := 0216 if request.Status == workflow.WorkflowExecutionCloseStatusCompleted {217 priority = 1 // low priority for completed workflows218 }219 return priority220}...

Full Screen

Full Screen

GetRateLimiter

Using AI Code Generation

copy

Full Screen

1import (2type Item struct {3}4func main() {5 sess, err := session.NewSession(&aws.Config{6 Region: aws.String("us-west-2")},7 svc := dynamodb.New(sess)8 av, err := dynamodbattribute.MarshalMap(Item{9 })10 if err != nil {11 fmt.Println("Got error marshalling map:")12 fmt.Println(err.Error())13 os.Exit(1)14 }15 input := &dynamodb.PutItemInput{16 TableName: aws.String("Movies"),17 }18 _, err = svc.PutItem(input)19 if err != nil {20 fmt.Println("Got error calling PutItem:")21 fmt.Println(err.Error())22 os.Exit(1)23 }24 fmt.Println("Successfully added 'janedoe' (25) to Movies table")25 result, err := svc.GetItem(&dynamodb.GetItemInput{26 TableName: aws.String("Movies"),27 Key: map[string]*dynamodb.AttributeValue{28 "Username": {29 S: aws.String("janedoe"),30 },31 "Age": {32 N: aws.String("25"),33 },34 },35 })36 if err != nil {37 fmt.Println("Got error calling GetItem:")38 fmt.Println(err.Error())39 os.Exit(1)40 }41 item := Item{}42 err = dynamodbattribute.UnmarshalMap(result.Item, &item)43 if err != nil {44 panic(fmt.Sprintf("Failed to unmarshal Record, %v", err))45 }46 fmt.Println("GetItem succeeded:")47 fmt.Println(item)48 input1 := &dynamodb.UpdateItemInput{49 ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{50 ":r": {51 N: aws.String("5"),52 },53 },

Full Screen

Full Screen

GetRateLimiter

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config := sarama.NewConfig()4 brokers := []string{"localhost:9092"}5 client, err := sarama.NewClient(brokers, config)6 if err != nil {7 panic(err)8 }9 limiter := client.GetRateLimiter()10 limiter.SetRate(100)11 limiter.SetBurst(1000)12 producer, err := sarama.NewAsyncProducerFromClient(client)13 if err != nil {14 panic(err)15 }16 defer func() {17 if err := producer.Close(); err != nil {18 panic(err)19 }20 }()21 for i := 0; i < 100; i++ {22 producer.Input() <- &sarama.ProducerMessage{Topic: topic, Value: sarama.StringEncoder(fmt.Sprintf("test %d", i))}23 }24 time.Sleep(10 * time.Second)25}

Full Screen

Full Screen

GetRateLimiter

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 pool, err := pgxpool.ConnectConfig(context.Background(), config)7 if err != nil {8 panic(err)9 }10 defer pool.Close()11 limiter := pool.GetRateLimiter()12 err = limiter.Wait(context.Background(), 1)13 if err != nil {14 panic(err)15 }16 rows, err := pool.Query(context.Background(), "SELECT 1")17 if err != nil {18 panic(err)19 }20 rows.Close()21 err = limiter.Wait(context.Background(), 2)22 if err != nil {23 panic(err)24 }25 batch := &pgx.Batch{}26 batch.Queue("SELECT 1")27 batch.Queue("SELECT 2")28 br := pool.SendBatch(context.Background(), batch)29 rows, err = br.Query()30 if err != nil {31 panic(err)32 }33 rows.Close()34 rows, err = br.Query()35 if err != nil {36 panic(err)37 }38 rows.Close()39 br.Close()40 err = limiter.Wait(context.Background(), 1)41 if err != nil {42 panic(err)43 }44 _, err = pool.Prepare(context.Background(), "my_stmt", "SELECT 1")45 if err != nil {46 panic(err)47 }48 rows, err = pool.Query(context.Background(), "my_stmt")49 if err != nil {50 panic(err)51 }52 rows.Close()53 err = limiter.Wait(context.Background(), 1)54 if err != nil {55 panic(err)56 }57 _, err = pool.CopyFrom(58 context.Background(),59 pgx.Identifier{"table"},60 []string{"a", "b"},61 pgx.CopyFromSlice(1, [][]interface{}{62 {pgtype.Int4{Int: 1, Status: pgtype.Present}, pgtype.Int4{

Full Screen

Full Screen

GetRateLimiter

Using AI Code Generation

copy

Full Screen

1rateLimiter := client.GetRateLimiter()2rateLimiter.SetRate(200)3rateLimiter.SetBurst(100)4rateLimiter := client.GetRateLimiter()5rateLimiter.SetRate(200)6rateLimiter.SetBurst(100)7rateLimiter := client.GetRateLimiter()8rateLimiter.SetRate(200)9rateLimiter.SetBurst(100)10rateLimiter := client.GetRateLimiter()11rateLimiter.SetRate(200)12rateLimiter.SetBurst(100)13rateLimiter := client.GetRateLimiter()14rateLimiter.SetRate(200)15rateLimiter.SetBurst(100)16rateLimiter := client.GetRateLimiter()17rateLimiter.SetRate(200)18rateLimiter.SetBurst(100)19rateLimiter := client.GetRateLimiter()20rateLimiter.SetRate(200)21rateLimiter.SetBurst(100)22rateLimiter := client.GetRateLimiter()23rateLimiter.SetRate(

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful