掛單是指在進入訂單簿后在市場上創造流動性的訂單。這意味著掛單不會在下單時成交,而是等待未來與之匹配的訂單。

另一方面,接受訂單會從市場中獲取流動性。它們通過與訂單簿中已下達的另一個訂單(即我們的訂單制作者)進行匹配來立即執行。

說到交易費用,當用戶將區塊鏈上的代幣轉移到 Bittrex 或從 Bittrex 轉移時,可能會產生一些特定的區塊鏈網絡費用。

Bittrex 不收取存款費,但收取取款費。

為什么我應該使用 Bittrex API?

為什么我不應該使用 Bittrex API?

Bittrex API 在我的國家/地區可用嗎?

由于監管要求,居住在某些國家/地區的客戶(見下圖)將無法再使用 Bittrex 平臺。此列表最后更新于 2021 年 3 月 23 日。

使用 Bittrex API 有哪些替代方案?

Bittrex 可以被其他更適合您需求的網站取代。以下是其中一些:

如何開始使用 Bittrex API?

為了開始使用 Bittrex API,您首先需要訪問其網站,網址為:

https://global.bittrex.com/

在右上角,你會看到“注冊”按鈕,請務必點擊它并選擇你的賬戶類型,填寫你的電子郵件和密碼。完成后,點擊藍色的“創建賬戶”按鈕。

接下來是檢查您的電子郵件中的驗證鏈接,之后您將進入 ToS(服務條款)頁面。

下一步是輸入您的基本帳戶信息,例如居住國家和出生詳細信息。之后,您需要驗證您的身份并提供一些其他信息。然后您需要等待幾天才能通過 Bittrex 進行全面驗證。

如何使用 Bittrex API 獲取貨幣數據?

可以通過訪問 Bittrex 貨幣端點,使用 Bittrex API 獲取 Bittrex 上的貨幣數據。為此,我們將使用 REST API。

response = pd.DataFrame(requests.get('https://api.bittrex.com/v3/currencies').json())
response.tail()

如您所見,Bittrex 上有 444 種可用貨幣,它們通常附帶“通知”消息,提供有關該貨幣的有用信息。

為了獲取有關特定貨幣的信息,您可以調用以下端點并在末尾說明您的貨幣名稱,如下所示:

btc = requests.get('https://api.bittrex.com/v3/currencies/BTC').json()
btc
{'symbol': 'BTC',
'name': 'Bitcoin',
'coinType': 'BITCOIN',
'status': 'ONLINE',
'minConfirmations': 2,
'notice': '',
'txFee': '0.00030000',
'IogoUrl': 'https://bittresblobstorage.blob.core.windows bef9.png',
'prohibitedIn': [],
'baseAddress': '1N52wHoVR79PMDishab2XmRHsbekCdGquK',
'associatedTermsOfServicel: [],
'tags': []}

如何在 Bittrex API 上獲取價格數據?

可以通過調用指定貨幣和/或該貨幣的市場行情端點來獲取 Bittrex API 的價格數據。

在我們訪問某個股票代碼之前,讓我們先看看 Bittrex 交易所上所有可用的市場(又稱交易對)是什么:

markets = pd.DataFrame(requests.get('https://api.bittrex.com/v3/markets').json())
markets.tail()

如您所見,Bittrex 上有超過 750 個可用的交易對。現在,讓我們獲取特定股票的價格數據。

ticker = requests.get('https://api.bittrex.com/v3/markets/BTC-USD/ticker').json()
ticker
{'symbol': 'BTCC-USD',
'last-TradeRate': '63552.35400000',
'bidRate': '63540.27100000',
'askRate': '63555.76000080'}

如果您想要所有可用交易對的價格數據,您可以編寫以下內容:

tickers = pd.DataFrame(requests.get('https://api.bittrex.com/v3/markets/tickers').json())
tickers.tail()

如何使用 Bittrex API 獲取歷史數據?

Bittrex API 可以通過訪問市場歷史端點來獲取歷史價格數據,用戶可以設置要獲取的起始日期、股票代碼和蠟燭間隔。

historical = pd.DataFrame(requests.get('https://api.bittrex.com/v3//markets/BTC-USD/candles/DAY_1/historical/2019').json())
historical.tail()

但是如果我們想用這些數據創建一些自定義指標和一個漂亮的交互式圖表該怎么辦呢?

如何使用 Bittrex API 訪問 20 SMA 等技術指標?

Bittrex API 沒有內置技術指標,但可以利用各種庫創建自定義指標。例如,我們可以使用 pandas 滾動窗口創建 20 天簡單移動平均線 (20 SMA)。

historical['20 SMA'] = historical.close.rolling(20).mean()
historical.tail()

對于更復雜的指標,您可以查看一個名為 btalib 的庫。現在,讓我們創建一個漂亮的交互式數據圖表。

import plotly.graph_objects as go
fig = go.Figure(data=[go.Candlestick(x = historical.index,
open = historical['open'],
high = historical['high'],
low = historical['low'],
close = historical['close'],
),
go.Scatter(x=historical.index, y=historical['20 SMA'], line=dict(color='purple', width=1))])

fig.show()

如何使用 Bittrex API 獲取訂單簿數據?

可以使用 Bittrex REST API 市場訂單簿端點獲取訂單簿數據。我還將向您展示如何為買入價和賣出價創建單獨的數據框或合并的數據框。

orderbook = requests.get('https://api.bittrex.com/v3/markets/BTC-USD/orderbook').json()

# If you want separate data frames
bids = pd.DataFrame(orderbook['bid'])
asks = pd.DataFrame(orderbook['ask'])

# You can also merge the two into one
df = pd.merge(bids, asks, left_index=True, right_index=True)
df = df.rename({"rate_x":"Bid Price","quantity_x":"Bid Amount",
"rate_y":"Ask Price","quantity_y":"Ask Amount"}, axis='columns')
df.head()

當 BTC 達到某個價格時,如何使用 Bittrex API 對 ETH 執行交易?

在第一個示例中,我將向您展示如何正確安全地啟動具有指定要求的訂單。我們想要做的是當 BTC 達到特定價格(例如 50,000 美元)時啟動 ETH 交易。

為了實現這一點,我們需要設置訂單基礎,然后創建一個循環來檢查價格水平是否被觸及。如果價格被觸及,我們將執行市價訂單。相反,我們將繼續循環。

當價格執行后,我們會等待幾秒鐘并檢查訂單是否真的已完成。這一額外步驟對于添加到您的交易策略中非常重要,因為交易所服務器可能會遇到一些問題。

我們還將創建一個自定義函數,使我們更容易處理需要身份驗證的 Bittrex 私有端點。

現在邏輯已經設置好了,讓我們導入相關的庫并設置交易:

import hmac
import time
import hashlib
import requests
import json
import pandas as pd

apiKey = ""
apiSecret = ""

def auth(uri, method, payload, apiKey, apiSecret):
timestamp = str(round(time.time()*1000))
contentHash = hashlib.sha512(payload).hexdigest()

array = [timestamp, uri, method, contentHash]
s= ''
preSign = s.join(str(v) for v in array)
signature = hmac.new(apiSecret.encode() ,preSign.encode(), hashlib.sha512).hexdigest()

headers = {
'Accept':'application/json',
'Api-Key':apiKey,
'Api-Timestamp':timestamp,
'Api-Content-Hash':contentHash,
'Api-Signature':signature,
'Content-Type':'application/json'
}

return headers

while True:
try:
ticker = requests.get('https://api.bittrex.com/v3/markets/BTC-USD/ticker').json()
except Exception as e:
print(f'Unable to obtain ticker data: {e}')

if float(ticker['bidRate']) >= 50000:

uri = 'https://api.bittrex.com/v3/orders'

content = { "marketSymbol":"USDC-ETH",
"direction":"SELL",
"type":"LIMIT",
"limit":"0.0005",
"quantity":"20",
"timeInForce":"GOOD_TIL_CANCELLED"
}

payload = bytes(json.dumps(content),'utf-8')

try:
data = requests.post(uri,
data=payload,
headers = auth(uri, 'POST', payload, apiKey, apiSecret),
timeout=10
).json()
print(data)
except Exception as e:
print(f'Unable to place order: {e}')

sleep(2)

try:
payload = ""
uri = f'https://api.bittrex.com/v3/orders/{data["id"]}'

check = requests.get(uri,
data=payload,
headers=auth(uri, 'GET', payload.encode(), apiKey, apiSecret),
timeout=10
).json()
print(check)
except Exception as e:
print(f'Unable to check order: {e}')

if check_order == 'OPEN':
print ('Order placed at {}'.format(pd.Timestamp.now()))
break
else:
print ('Order closed at {}'.format(pd.Timestamp.now()))
break
else:
sleep(60)
continue

請注意:如果您想交易其他美元對,符號通常會按相反的順序排列,例如“ETH-USDT”。

當 BTC 在過去 5 分鐘內波動 5% 時,如何使用 Bittrex API 執行 ETH 交易?

主要任務是當 BTC 在過去 5 分鐘內波動 5% 時執行 ETH 交易。這意味著我們需要創建一個循環,以在特定間隔內獲取 BTC 價格并計算它們之間的百分比變化。

如果百分比變化小于 5%,腳本將休眠 5 分鐘并再次計算百分比變化。如果百分比變化等于或大于 5%,則交易將執行。

交易執行后,我們將休眠幾秒鐘,然后檢查交易是否已完成。請記住,循環部分的代碼與上一個示例相同。

現在已經設置了邏輯,是時候編寫代碼了:

while True:
try:
btc_old = requests.get('https://api.bittrex.com/v3/markets/BTC-USD/ticker').json()
except Exception as e:
print(f'Unable to obtain ticker data: {e}')

sleep(300)

try:
btc_new = requests.get('https://api.bittrex.com/v3/markets/BTC-USD/ticker').json()
except Exception as e:
print(f'Unable to obtain ticker data: {e}')

percent = (((float(btc_new['bidRate']) - float(btc_old['bidRate'])) * 100) / float(btc_old['bidRate']))

if percent >= 5:

uri = 'https://api.bittrex.com/v3/orders'

content = { "marketSymbol":"USDC-ETH",
"direction":"SELL",
"type":"LIMIT",
"limit":"0.0005",
"quantity":"20",
"timeInForce":"GOOD_TIL_CANCELLED"
}

payload = bytes(json.dumps(content),'utf-8')

try:
data = requests.post(uri,
data=payload,
headers = auth(uri, 'POST', payload, apiKey, apiSecret),
timeout=10
).json()
print(data)
except Exception as e:
print(f'Unable to place order: {e}')

sleep(2)

try:
payload = ""
uri = f'https://api.bittrex.com/v3/orders/{data["id"]}'

check = requests.get(uri,
data=payload,
headers=auth(uri, 'GET', payload.encode(), apiKey, apiSecret),
timeout=10
).json()
print(check)
except Exception as e:
print(f'Unable to check order: {e}')

if check_order == 'OPEN':
print ('Order placed at {}'.format(pd.Timestamp.now()))
break
else:
print ('Order closed at {}'.format(pd.Timestamp.now()))
break
else:
print(f'Requirment not reached. Percentage move at {percent}')
continue

如何使用 Bittrex API 取消訂單?

要取消 Bittrex 的訂單,您需要使用 DELETE 訂單端點并傳遞要取消的訂單的訂單 ID。為此,您可以參考我們之前的示例:

uri = "https://api.bittrex.com/v3/orders/{orderId}"
payload = ""
data = requests.delete(uri,
data=payload,
headers = auth(uri, 'DELETE', payload.encode(), apiKey, apiSecret),
timeout=10
).json()

Bittrex API 可以在 Google Sheets 中使用嗎?

是的,您可以通過編寫一個簡單的 JS 腳本在 Google Sheets 中使用 Bittrex API,該腳本對響應執行與我們的 Python 代碼相同的操作。我將向您展示一個示例腳本,該腳本提取我們資產的最新股票價格。

我們需要做的第一件事是打開一個空白的 Google Sheets 表,然后轉到工具并選擇下拉菜單中出現的腳本編輯器。

到達那里后,您將復制以下代碼并單擊保存圖標:

function Ticker_Last(symbol)
{
var url = "https://api.bittrex.com/v3/markets/" + symbol + "/ticker";
var response = UrlFetchApp.fetch(url);
var myjson = JSON.parse(response.getContentText());
var lastprice = myjson.lastTradeRate;
return lastprice;
}

現在您可以返回工作表并將您感興趣的加密貨幣添加到單元格中。完成后,您可以使用以下函數提取最新價格數據:

=Ticker_Last(<cell>)

上一篇:

Etherscan API:分步指南

下一篇:

OKX API – 入門指南
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數據驅動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內容創意新穎性、情感共鳴力、商業轉化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費