Dave-Vallance / bt-ccxt-store

Fork of Ed Bartosh's CCXT Store Work
MIT License
423 stars 187 forks source link

How to get current price in Strategy's next? #40

Open mr-m0nst3r opened 3 years ago

mr-m0nst3r commented 3 years ago

Hi there,

I need to get current market price in the next function to make decisions.

Tried to change ccxt/ccxtstore.py, add some code to get fetch_ticket information.

def __init__(self, exchange, currency, config, retries, debug=False, sandbox=False):
        self.exchange = getattr(ccxt, exchange)(config)
        # print("self.exchange",self.exchange)
        print("self.exchange.fetch_ticker", self.exchange.fetch_ticker('USDT/HUSD'))

Here's the output:

self.exchange.fetch_ticker {'symbol': 'USDT/HUSD', 'timestamp': 1615448013555, 'datetime': '2021-03-11T07:33:33.555Z', 'high': 1.0006, 'low': 0.9995, 'bid': 0.9997, 'bidVolume': 42300.4802, 'ask': 0.9998, 'askVolume': 136145.3142, 'vwap': 1.000125720339054, 'open': 1.0004, 'close': 0.9997, 'last': 0.9997, 'previousClose': None, 'change': -0.0006999999999999229, 'percentage': -0.06997201119551409, 'average': 1.0000499999999999, 'baseVolume': 105604769.11847508, 'quoteVolume': 105618045.78585435, 'info': {'amount': 105604769.11847508, 'open': 1.0004, 'close': 0.9997, 'high': 1.0006, 'id': 208846147104, 'count': 79494, 'low': 0.9995, 'version': 208846147104, 'ask': [0.9998, 136145.3142], 'vol': 105618045.78585435, 'bid': [0.9997, 42300.4802]}}
2021-03-11 15:33:42.040526 USDTHUSD Data Status: DELAYED, Order Status: 3
2021-03-11 15:33:44.140944 USDTHUSD Data Status: LIVE, Order Status: 4
2021-03-11, DIFF = HIGH - SMA30: 0.0

But I'm confused how should I call it in the Strategy's next function.

Any suggestions?

Thanks a lot.