The RestAPI allows you to place orders and fetch market or account data. You can use specialized API classes (like OrderApi) or the base BitgetApi class to make direct POST or GET requests.
Important for RSA users: If your API key is of the RSA type, you must manually set the signature type to RSA in the constans.py file by setting SIGN_TYPE = RSA.
import bitget.v1.mix.order_api as maxOrderApi
import bitget.bitget_api as baseApi
from bitget.exceptions import BitgetAPIException
if __name__ == '__main__':
apiKey = ""
secretKey = '''your'''
passphrase = ""
# Demo 1: Place an order using a specialized API class
maxOrderApi = maxOrderApi.OrderApi(apiKey, secretKey, passphrase)
try:
params = {
"symbol": "BTCUSDT_UMCBL",
"marginCoin": "USDT",
"side": "open_long",
"orderType": "limit",
"price": "27012",
"size": "0.01",
"timInForceValue": "normal"
}
response = maxOrderApi.placeOrder(params)
print(response)
except BitgetAPIException as e:
print("error:" + e.message)
# Demo 2: Place an order by calling the POST method directly
baseApi = baseApi.BitgetApi(apiKey, secretKey, passphrase)
try:
params = {
"symbol": "BTCUSDT_UMCBL",
"marginCoin": "USDT",
"side": "open_long",
"orderType": "limit",
"price": "27012",
"size": "0.01",
"timInForceValue": "normal"
}
response = baseApi.post("/api/mix/v1/order/placeOrder", params)
print(response)
except BitgetAPIException as e:
print("error:" + e.message)
# Demo 3: Send a GET request for market data
try:
params = {"productType": "umcbl"}
response = baseApi.get("/api/mix/v1/market/contracts", params)
print(response)
except BitgetAPIException as e:
print("error:" + e.message)
# Demo 4: Send a GET request with no parameters
try:
response = baseApi.get("/api/spot/v1/account/getInfo", {})
print(response)
except BitgetAPIException as e:
print("error:" + e.message)