Skip to content
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

Open
huwei1024 opened this issue Feb 10, 2023 · 2 comments
Open

Why is the entry_price wrong? #222

huwei1024 opened this issue Feb 10, 2023 · 2 comments
Labels
futures Anything related to the futures bugs

Comments

@huwei1024
Copy link

the entry_price in position.exchange_specific is not correct?
it seems 100 times of price?

exchange = futures.BinanceFutures()
strategy = futures.FuturesStrategy(exchange)

state.interface.limit_order(
    symbol, price=price, side=side, size=order_size)

```

@EmersonDove EmersonDove self-assigned this Feb 12, 2023
@EmersonDove EmersonDove added the futures Anything related to the futures bugs label Feb 12, 2023
@EmersonDove EmersonDove removed their assignment Feb 12, 2023
@EmersonDove
Copy link
Member

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.

@huwei1024
Copy link
Author

huwei1024 commented Feb 13, 2023

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:
order size:500 price:0.08198 side:Side.BUY
{'symbol': 'DOGE-USDT', 'base_asset': 'DOGE', 'quote_asset': 'USDT', 'size': 500.0, 'position': <PositionMode.BOTH: 'both'>, 'leverage': 1, 'margin_type': <MarginType.CROSSED: 'crossed'>, 'contract_type': <ContractType.PERPETUAL: 'perpetual'>, 'exchange_specific': {'entry_price': 41.006396}}
entry_price:41.00640 price:0.08173'

the 'entry_price' is total amount?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
futures Anything related to the futures bugs
Projects
None yet
Development

No branches or pull requests

2 participants