表題の通り、FTXで注文したあと、
損益を確認する処理をBotに組み込みたくて四苦八苦したのでメモ。
ビットフライヤーのAPIでは、
「”pnl”」の項目があるので現在のポジションの損益把握は簡単でした。
Bitmexでもエントリ時の価格が出力されるので、現在価格から損益が計算できました。
FTXの場合、CCXTからポジションを取得すると以下のようになります。
1 2 | position=ccxtAPIobj().private_get_positions() pprint(position['result']) |
この場合の実行結果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [{'collateralUsed':4.26348, 'cost':42.6348, 'entryPrice':71058.0, #→エントリ時の価格に見えるが、現在価格になっている 'estimatedLiquidationPrice':0.0, 'future':'BTC-1231', 'initialMarginRequirement':0.1, 'longOrderSize':0.0, 'maintenanceMarginRequirement':0.03, 'netSize':0.0006, 'openSize':0.0006, 'realizedPnl':-80.8541, 'shortOrderSize':0.0, 'side':'buy', 'size':0.0006, 'unrealizedPnl':0.0}] |
この場合、スクリプトの中でエントリ時の価格をpickle化しておくしか思いつかない。
参りました。
対処
showAvgPriceパラメータを指定すると、
「recentBreakEvenPrice」が損益分岐点として表示されるように見える。
1 2 3 | print("#ポジションの取得") position=ccxtAPIobj().private_get_positions({'showAvgPrice':True}) pprint(position['result']) |
修正後の実行結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [{'collateralUsed':4.28208, 'cost':42.8208, 'cumulativeBuySize':0.0006, 'cumulativeSellSize':0.0, 'entryPrice':71368.0, 'estimatedLiquidationPrice':0.0, 'future':'BTC-1231', 'initialMarginRequirement':0.1, 'longOrderSize':0.0, 'maintenanceMarginRequirement':0.03, 'netSize':0.0006, 'openSize':0.0006, 'realizedPnl':-80.6681, <strong>'recentAverageOpenPrice':64418.333333333336,</strong> <strong>'recentBreakEvenPrice':64418.333333333336,</strong> 'recentPnl':4.1698, 'shortOrderSize':0.0, 'side':'buy', 'size':0.0006, 'unrealizedPnl':0.0}] |
上記で現在価格から損益が計算できそうなので、これでBotに組み込んで見ようと思います。
コメント