Skip to content

Commit

Permalink
Fixes to getting alpaca tickers.
Browse files Browse the repository at this point in the history
Version update.

Changes to be committed:
	modified:   Base/JackrabbitLocker
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/JackrabbitRelay
	modified:   Base/Library/JRRccxt.py
	modified:   Base/Library/JackrabbitRelay.py
	modified:   Extras/ListMarkets
  • Loading branch information
rapmd73 committed Sep 22, 2023
1 parent 7b63d99 commit 00f4c2a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Base/JackrabbitLocker
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import json

import JRRsupport

Version="0.0.0.1.400"
Version="0.0.0.1.425"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
2 changes: 1 addition & 1 deletion Base/JackrabbitOliverTwist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import subprocess
import JRRsupport
import JackrabbitRelay as JRR

Version="0.0.0.1.400"
Version="0.0.0.1.425"
BaseDirectory='/home/JackrabbitRelay2/Base'
DataDirectory='/home/JackrabbitRelay2/Data'
ConfigDirectory='/home/JackrabbitRelay2/Config'
Expand Down
2 changes: 1 addition & 1 deletion Base/JackrabbitRelay
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import json

import JRRsupport

Version="0.0.0.1.400"
Version="0.0.0.1.425"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
69 changes: 30 additions & 39 deletions Base/Library/JRRccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,54 +314,45 @@ def GetOHLCV(self,**kwargs):
return self.Results

def GetTicker(self,**kwargs):
if self.Broker.has['fetchTickers']==False:
symbol=kwargs.get('symbol')
tf=list(self.Broker.timeframes.keys())[0]
ohlcv=self.GetOHLCV(symbol=symbol,timeframe=tf,limit=1)
if ohlcv==[]:
bid=0
ask=0
else:
bid=ohlcv[0][4]
ask=ohlcv[0][1]
else:
# Best case situation, exchange has a ticker api.

if self.Broker.has['fetchTickers']==True:
self.Results=self.API("fetch_ticker",**kwargs)
print(self.Results)
bid=self.Results['bid']
ask=self.Results['ask']
# Last resort
o=self.Results['open']
c=self.Results['close']

# Kucoin/Binance system doesn't always give complete data
# This is an absolute crap way of faking it, but the only way I've come up with.
else:
# Worst case situation, pull the orderbook. takes at least 5 seconds.
symbol=kwargs.get('symbol')
ob=self.GetOrderBook(symbol=symbol)
if (ob['bids']==None or ob['bids']==[]):
if (ob['asks']==None or ob['asks']==[]):
bid=None
else:
bid=ob['asks'][0][0]
else:
bid=ob['bids'][0][0]

if (bid==None or ask==None):
# Worst case situation, pull the orderbook. takes at least 5 seconds.
symbol=kwargs.get('symbol')
ob=self.GetOrderBook(symbol=symbol)
if (ob['asks']==None or ob['asks']==[]):
if (ob['bids']==None or ob['bids']==[]):
if (ob['asks']==None or ob['asks']==[]):
bid=None
else:
bid=ob['asks'][0][0]
ask=None
else:
bid=ob['bids'][0][0]
ask=ob['bids'][0][0]
else:
ask=ob['asks'][0][0]

if (ob['asks']==None or ob['asks']==[]):
if (ob['bids']==None or ob['bids']==[]):
ask=None
else:
ask=ob['bids'][0][0]
else:
ask=ob['asks'][0][0]
# Absolute worst case situation, orderbook is empty... Thank you ALPACA

if (bid==None or ask==None):
if o!=None and c!=None:
bid=max(o,c)
ask=min(o,c)
else:
if bid==None or ask==None:
symbol=kwargs.get('symbol')
tf=list(self.Broker.timeframes.keys())[0]
ohlcv=self.GetOHLCV(symbol=symbol,timeframe=tf,limit=1)
if ohlcv==[]:
bid=0
ask=0
else:
bid=ohlcv[0][4]
ask=ohlcv[0][1]

Pair={}
Pair['DateTime']=datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
Expand Down Expand Up @@ -400,7 +391,7 @@ def GetOpenTrades(self,**kwargs):
# symbol, type, side (action), amount, price, params

# PlaceOrder(exchange, Active, pair=pair, orderType=orderType,
# action=action, amount=amount, close=close, ReduceOnly=ReduceOnly,
# action=action, amount=amount, close=close, ReduceOnly=ReduceOnly,
# LedgerNote=ledgerNote)

def PlaceOrder(self,**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitRelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def Success(self,f,s):
class JackrabbitRelay:
def __init__(self,framework=None,payload=None,exchange=None,account=None,asset=None,secondary=None,NoIdentityVerification=False,Usage=None):
# All the default locations
self.Version="0.0.0.1.400"
self.Version="0.0.0.1.425"
self.NOhtml='<html><title>NO!</title><body style="background-color:#ffff00;display:flex;weight:100vw;height:100vh;align-items:center;justify-content:center"><h1 style="color:#ff0000;font-weight:1000;font-size:10rem">NO!</h1></body></html>'
self.BaseDirectory='/home/JackrabbitRelay2/Base'
self.ConfigDirectory='/home/JackrabbitRelay2/Config'
Expand Down
10 changes: 6 additions & 4 deletions Extras/ListMarkets
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ def main():
if pair.find(srch)<0:
continue

# print(relay.Markets[pair])

ticker=relay.GetTicker(symbol=pair)

# If bid and ask are 0, we can't trade it, so don't show it.
if ticker['Bid']==0 and ticker['Ask']==0:
continue

if relay.Framework=='ccxt':
marketType=relay.Markets[pair]['type']
if 'margin' in relay.Markets[pair] and relay.Markets[pair]['margin']==True \
and marketType=='spot':
marketType='margin'
id=relay.Markets[pair]['id']
print(f"{pair:30} {id:30} {marketType:8} {ticker['Ask']:18.8f} {ticker['Spread']:18.8f} {ticker['Bid']:18.8f}")
print(f"{pair:30} {id:30} {marketType:8} {ticker['Bid']:18.8f} {ticker['Spread']:18.8f} {ticker['Ask']:18.8f}")
elif relay.Framework=='oanda':
mr=GetRatio(float(relay.Markets[pair]['marginRate']))
print(f"{pair:30} {mr} {ticker['Ask']:9.5f} {ticker['Spread']:9.5f} {ticker['Bid']:9.5f}")
print(f"{pair:30} {mr} {ticker['Bid']:9.5f} {ticker['Spread']:9.5f} {ticker['Ask']:9.5f}")
else:
print("Unrecognized framework")
sys.exit(0)
Expand Down

0 comments on commit 00f4c2a

Please sign in to comment.