Python code to trade cryptocurrencies using bitmex APIs
$10-30 USD
Fullført
Lagt ut over 3 år siden
$10-30 USD
Betalt ved levering
Currently I have a program that I got on the internet and I want to fix it.
the program is written in python and is made to interact with bitmex through its API and Key.
The program must do the following 6 things:
1) show candlesticks from a specific period
2) calculate the simple moving average
3) show bid and ask from order book
4) show balances
5) cancel orders
6) place orders
for better understanding I am attaching part the program that I have:
class bitmex(object):
BASE_URL = "[login to view URL]"
KEY = "XXX"
SECRET = "ZZZ"
def sma(self,candles,period):
if len(candles)>=period:
sma=[]
added=0.0
i=period-1
j=0
i_temp=0
while j<len(candles)-period+1:
i_temp=i
added=0
while i>=j:
added=added+candles[i]
i-=1
[login to view URL](added/period)
i=i_temp
i+=1
j+=1
for avg in sma:
print("Simple Moving Average : ", avg)
return sma
def candlestick(self):
url = self.BASE_URL + "/trade/bucketed?binSize=5m&partial=false&symbol=XBTUSD&count=100&reverse=false"
response = [login to view URL]("GET", url)
if response.status_code == 200:
data=[login to view URL]()
candles=[]
for ohlc in data:
if str(ohlc["close"])!="None":
[login to view URL](ohlc["close"])
if len(candles)>0:
[login to view URL](candles,20)
else:
print('error, status_code = ', response.status_code)
def _nonce(self):
return str(int(round([login to view URL]()) + 5))
def _signer(self,verb, url, expires, data):
parsedURL = urlparse(url)
path = [login to view URL]
if [login to view URL]:
path = path + '?' + [login to view URL]
if isinstance(data, (bytes, bytearray)):
data = [login to view URL]('utf8')
message = verb + path + str(expires) + data
return [login to view URL]([login to view URL]('utf8'),[login to view URL]('utf8'),digestmod=[login to view URL]).hexdigest()
def _headers(self,verb, path, expires, data):
return {
"api-expires": str(expires),
"api-key": [login to view URL],
"api-signature": self._signer(verb, path, expires, data),
}
def balance(self):
nonce=self._nonce()
verb='GET'
path="/api/v1/user/margin"
data={
'currency': 'XRP'
}
headers=self._headers(verb,path,nonce,'')
response = [login to view URL](self.BASE_URL + "/user/margin",headers=headers,data=[login to view URL](data),verify=True)
if response.status_code == 200:
data=[login to view URL]()
if data["currency"]=="XBt":
print("Balance XBt : ",data["amount"])
else:
data=[login to view URL]()
print('error, status_code = ', response.status_code)
def neworder(self):
nonce=self._nonce()
verb='POST'
path="/api/v1/order"
data={
'symbol': 'XBTUSD',
'side': 'Buy',
'orderQty': '0.0',
'price': '0',
'ordType': 'Limit'
}
headers=self._headers(verb,path,nonce,'')
response = [login to view URL](self.BASE_URL + "/order",headers=headers,data=[login to view URL](data),verify=True)
if response.status_code == 200:
data=[login to view URL]()
print(data)
else:
data=[login to view URL]()
print(data)
print('error, status_code = ', response.status_code)
I have a lot of experience in this field.
I am trader and also build trading systems.
Right now I have a trading bot working with the broker Kraken, making more than 6% a month.
I understand the cryptomarket on a deep level because I am constantly tinkering with my own trading bots everyday.
On top of that, I am a funded day trader on the futures market so I also have a deep understanding of practical trading strategies that actually work(as I use them 5 days a week).
Playing the financial markets is my passion.
I would love to help and ensure your desired outcome.
Thank you for spending the time to reading this.
Have an amazing day.