New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is the entry_price wrong? #222
Comments
I'm not sure, can you give more examples of which symbols you're calling and the context? I'm not sure I can diagnose with just this information. |
this code below import blankly
from blankly import futures, Side
from blankly.futures import FuturesStrategyState
from blankly.futures.utils import close_position
def price_event(price, symbol, state: FuturesStrategyState):
position = state.interface.get_position(symbol)
his = state.variables.history
his.append(price)
# print(position)
current_size = 0
entry_price = 0
if position:
current_size = position['size']
entry_price = float(position['exchange_specific']['entry_price'])
print(position)
state.variables['prev_price'] = price
# print(position)
print('entry_price:%1.5f price:%1.5f' %
(entry_price, price))
side = Side.BUY
size = 0
if current_size < 0:
size = abs(current_size)
side = Side.BUY
elif current_size > 0:
size = current_size
side = Side.SELL
else:
size = 500
if size > 0:
print('order size:%s price:%1.5f side:%s' %
(size, price, side))
state.interface.limit_order(
symbol, price=price, side=side, size=size)
# This function will be run before our algorithm starts
def init(symbol, state: FuturesStrategyState):
# Close any open positions
close_position(symbol, state)
# Give the algo the previous price as context
last_price = state.interface.history(
symbol, to=1, return_as='deque', resolution=state.resolution)['close'][-1]
state.variables['prev_price'] = last_price
# Download price data to give context to the algo
state.variables.history = state.interface.history(symbol, to=1440, return_as='deque',
resolution=state.resolution)['close']
if __name__ == "__main__":
exchange = futures.BinanceFutures()
strategy = futures.FuturesStrategy(exchange)
strategy.add_price_event(
price_event, init=init, symbol='DOGE-USDT', resolution='1h')
if blankly.is_deployed:
strategy.start()
else:
result = strategy.backtest(to='1d', initial_values={'USDT': 1000})
print(result) then i got log: the 'entry_price' is total amount? |
the entry_price in position.exchange_specific is not correct?
it seems 100 times of price?
The text was updated successfully, but these errors were encountered: