Categorygithub.com/go-numb/go-bitmex
repositorypackage
0.0.0-20200425051953-4d04529e09a3
Repository: https://github.com/go-numb/go-bitmex.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Bitmex REST/Realtime APIs for Go

Fork & Tribute

github@zmxv

Overview

This go-bitmex package enables golang clients to call REST APIs for the Bitmex crypto trading platform. It fixes critical bugs in the swagger-generated code and enhances its usability.

Notable changes:

  • Fixed the authentication logic and API endpoint
  • Fixed form data encoding
  • Renamed the package from swagger to bitmex
  • Removed all external dependencies (golang.org/x/oauth2 and github.com/antihax/optional)
  • Added a local optional package with mutable states to simplify parameter assignment
  • Fixed many type issues and removed the obsolete XAny type

This package also differs from an alternative library at https://github.com/qct/bitmex-go in the following ways:

  • bitmex employs strongly-typed structs for API parameters instead of map[string]interface{}.
  • bitmex is forked from a more recent version of the swagger-generated code.
  • bitmex depends on no external packages and is compatible with Google App Engine.

Installation

$ go get github.com/go-numb/go-bitmex

Usage

import "github.com/go-numb/go-bitmex"

const (
    // Get your API key/secret pair at https://www.bitmex.com/app/apiKeys
    key := "<API_KEY>"
    secret := "<API_SECRET>"
    isTestNet = false
)

func main() {

    // Create an authentication context
    auth := bitmex.NewAPIKeyContext(key, secret)

    // Create a shareable API client instance
    client := bitmex.NewAPIClient(bitmex.NewConfiguration())
    if isTestNet {
        // Create a testnet API client instance
        client := bitmex.NewAPIClient(bitmex.NewTestnetConfiguration())
    }

    // Manager API Limit
    isPrivate := true
    publicAPI := bitmex.NewLimit(!isPrivate)
    privateAPI := bitmex.NewLimit(isPrivate)


    // Call APIs without parameters by passing the auth context.
    // e.g. getting exchange-wide turnover and volume statistics:
    stats, res, err := client.StatsApi.StatsGet(auth)

    // gets API Remain from header x-ratelimit-remain & more
    publicAPI.FromHeader(res.Header)

    // Call APIs with default parameters by passing the auth context and a nil.
    // e.g. getting all open positions:
    pos, res, err := client.PositionApi.PositionGet(auth, nil)

    // gets API Remain from header x-ratelimit-remain & more
    publicAPI.FromHeader(res.Header)

    // Call APIs with additional parameters by constructing a corresponding XXXOpts struct.
    // e.g. submitting a limit order to buy 20000 contracts of XBTUSD at $6000.5:
    var params bitmex.OrderNewOpts
    params.OrdType.Set("Limit")
    params.Side.Set("Buy")
    params.OrderQty.Set(20000)
    params.Price.Set(6000.5)

    // checks API Limit
    if err := privateAPI.Check();err != nil {
        return
    }

    // order with params
    order, res, err := client.OrderApi.OrderNew(auth, "XBTUSD", &params)
    
    // gets API Remain from header x-ratelimit-remain & more
    privateAPI.FromHeader(res.Header)
}

Documentation for API Endpoints

All URIs are relative to https://www.bitmex.com/api/v1

ClassMethodHTTP requestDescription
APIKeyApiAPIKeyDisablePost /apiKey/disableDisable an API Key.
APIKeyApiAPIKeyEnablePost /apiKey/enableEnable an API Key.
APIKeyApiAPIKeyGetGet /apiKeyGet your API Keys.
APIKeyApiAPIKeyNewPost /apiKeyCreate a new API Key.
APIKeyApiAPIKeyRemoveDelete /apiKeyRemove an API Key.
AnnouncementApiAnnouncementGetGet /announcementGet site announcements.
AnnouncementApiAnnouncementGetUrgentGet /announcement/urgentGet urgent (banner) announcements.
ChatApiChatGetGet /chatGet chat messages.
ChatApiChatGetChannelsGet /chat/channelsGet available channels.
ChatApiChatGetConnectedGet /chat/connectedGet connected users.
ChatApiChatNewPost /chatSend a chat message.
ExecutionApiExecutionGetGet /executionGet all raw executions for your account.
ExecutionApiExecutionGetTradeHistoryGet /execution/tradeHistoryGet all balance-affecting executions. This includes each trade, insurance charge, and settlement.
FundingApiFundingGetGet /fundingGet funding history.
InstrumentApiInstrumentGetGet /instrumentGet instruments.
InstrumentApiInstrumentGetActiveGet /instrument/activeGet all active instruments and instruments that have expired in <24hrs.
InstrumentApiInstrumentGetActiveAndIndicesGet /instrument/activeAndIndicesHelper method. Gets all active instruments and all indices. This is a join of the result of /indices and /active.
InstrumentApiInstrumentGetActiveIntervalsGet /instrument/activeIntervalsReturn all active contract series and interval pairs.
InstrumentApiInstrumentGetCompositeIndexGet /instrument/compositeIndexShow constituent parts of an index.
InstrumentApiInstrumentGetIndicesGet /instrument/indicesGet all price indices.
InsuranceApiInsuranceGetGet /insuranceGet insurance fund history.
LeaderboardApiLeaderboardGetGet /leaderboardGet current leaderboard.
LeaderboardApiLeaderboardGetNameGet /leaderboard/nameGet your alias on the leaderboard.
LiquidationApiLiquidationGetGet /liquidationGet liquidation orders.
NotificationApiNotificationGetGet /notificationGet your current notifications.
OrderApiOrderAmendPut /orderAmend the quantity or price of an open order.
OrderApiOrderAmendBulkPut /order/bulkAmend multiple orders for the same symbol.
OrderApiOrderCancelDelete /orderCancel order(s). Send multiple order IDs to cancel in bulk.
OrderApiOrderCancelAllDelete /order/allCancels all of your orders.
OrderApiOrderCancelAllAfterPost /order/cancelAllAfterAutomatically cancel all your orders after a specified timeout.
OrderApiOrderClosePositionPost /order/closePositionClose a position. [Deprecated, use POST /order with execInst: 'Close']
OrderApiOrderGetOrdersGet /orderGet your orders.
OrderApiOrderNewPost /orderCreate a new order.
OrderApiOrderNewBulkPost /order/bulkCreate multiple new orders for the same symbol.
OrderBookApiOrderBookGetL2Get /orderBook/L2Get current orderbook in vertical format.
PositionApiPositionGetGet /positionGet your positions.
PositionApiPositionIsolateMarginPost /position/isolateEnable isolated margin or cross margin per-position.
PositionApiPositionTransferIsolatedMarginPost /position/transferMarginTransfer equity in or out of a position.
PositionApiPositionUpdateLeveragePost /position/leverageChoose leverage for a position.
PositionApiPositionUpdateRiskLimitPost /position/riskLimitUpdate your risk limit.
QuoteApiQuoteGetGet /quoteGet Quotes.
QuoteApiQuoteGetBucketedGet /quote/bucketedGet previous quotes in time buckets.
SchemaApiSchemaGetGet /schemaGet model schemata for data objects returned by this API.
SchemaApiSchemaWebsocketHelpGet /schema/websocketHelpReturns help text & subject list for websocket usage.
SettlementApiSettlementGetGet /settlementGet settlement history.
StatsApiStatsGetGet /statsGet exchange-wide and per-series turnover and volume statistics.
StatsApiStatsHistoryGet /stats/historyGet historical exchange-wide and per-series turnover and volume statistics.
StatsApiStatsHistoryUSDGet /stats/historyUSDGet a summary of exchange statistics in USD.
TradeApiTradeGetGet /tradeGet Trades.
TradeApiTradeGetBucketedGet /trade/bucketedGet previous trades in time buckets.
UserApiUserCancelWithdrawalPost /user/cancelWithdrawalCancel a withdrawal.
UserApiUserCheckReferralCodeGet /user/checkReferralCodeCheck if a referral code is valid.
UserApiUserConfirmPost /user/confirmEmailConfirm your email address with a token.
UserApiUserConfirmEnableTFAPost /user/confirmEnableTFAConfirm two-factor auth for this account. If using a Yubikey, simply send a token to this endpoint.
UserApiUserConfirmWithdrawalPost /user/confirmWithdrawalConfirm a withdrawal.
UserApiUserDisableTFAPost /user/disableTFADisable two-factor auth for this account.
UserApiUserGetGet /userGet your user model.
UserApiUserGetAffiliateStatusGet /user/affiliateStatusGet your current affiliate/referral status.
UserApiUserGetCommissionGet /user/commissionGet your account's commission status.
UserApiUserGetDepositAddressGet /user/depositAddressGet a deposit address.
UserApiUserGetMarginGet /user/marginGet your account's margin status. Send a currency of &quot;all&quot; to receive an array of all supported currencies.
UserApiUserGetWalletGet /user/walletGet your current wallet information.
UserApiUserGetWalletHistoryGet /user/walletHistoryGet a history of all of your wallet transactions (deposits, withdrawals, PNL).
UserApiUserGetWalletSummaryGet /user/walletSummaryGet a summary of all of your wallet transactions (deposits, withdrawals, PNL).
UserApiUserLogoutPost /user/logoutLog out of BitMEX.
UserApiUserLogoutAllPost /user/logoutAllLog all systems out of BitMEX. This will revoke all of your account's access tokens, logging you out on all devices.
UserApiUserMinWithdrawalFeeGet /user/minWithdrawalFeeGet the minimum withdrawal fee for a currency.
UserApiUserRequestEnableTFAPost /user/requestEnableTFAGet secret key for setting up two-factor auth.
UserApiUserRequestWithdrawalPost /user/requestWithdrawalRequest a withdrawal to an external wallet.
UserApiUserSavePreferencesPost /user/preferencesSave user preferences.
UserApiUserUpdatePut /userUpdate your password, name, and other attributes.

Documentation For Models

Author

@_numbP

Bitmex customer support

[email protected]