-
Notifications
You must be signed in to change notification settings - Fork 2
/
binance_client.py
45 lines (38 loc) · 1.21 KB
/
binance_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import logging
from binance.spot import Spot as Client
from binance.error import ClientError
api_key = ""
api_secret = ""
client = Client(api_key, api_secret)
def handle_trade_error(action, error):
error_text = "Trade error. Action: {}. Status: {}. Error code: {}. Error message: {}".format(
action, error.status_code, error.error_code, error.error_message
)
logging.error(error_text)
def margin_send_market_buy_order(symbol, quantity):
params = {
"symbol": symbol,
"side": "BUY",
"type": "MARKET",
"quantity": quantity,
"isIsolated": "TRUE",
}
try:
response = client.new_margin_order(**params)
logging.info(response)
except ClientError as error:
handle_trade_error("Market Buy", error)
def margin_send_market_sell_order(symbol, quantity):
params = {
"symbol": symbol,
"side": "SELL",
"type": "MARKET",
"quantity": quantity,
"isIsolated": "TRUE",
}
try:
response = client.new_margin_order(**params)
logging.info(response)
except ClientError as error:
handle_trade_error("Market Sell", error)