-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(
bot-processor
): pass candle and candles history to context
- Loading branch information
Showing
19 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { USE_MARKET, USE_CANDLE } from "./types"; | ||
import { makeEffect } from "./utils"; | ||
|
||
export function useMarket() { | ||
return makeEffect(USE_MARKET, undefined, undefined); | ||
} | ||
|
||
/** | ||
* Get candle data for the given index. | ||
* If the index is negative, it will return the candle data from the end. | ||
* By default, will return the last candle. | ||
*/ | ||
export function useCandle(index = -1) { | ||
return makeEffect(USE_CANDLE, index, undefined); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./bot"; | ||
export * from "./smart-trade"; | ||
export * from "./store"; | ||
export * from "./market"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./market-data"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ICandlestick } from "@opentrader/types"; | ||
|
||
export interface MarketData { | ||
/** | ||
* Lst closed candlestick | ||
*/ | ||
candle?: ICandlestick; | ||
/** | ||
* List of previous candles, included last one. Last candle can be accessed by `candles[candles.length - 1]` | ||
*/ | ||
candles: ICandlestick[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { IExchange } from "@opentrader/exchanges"; | ||
import type { MarketData, TBotContext } from "@opentrader/bot-processor"; | ||
import { useMarket, useCandle, useExchange } from "@opentrader/bot-processor"; | ||
import { logger } from "@opentrader/logger"; | ||
|
||
export function* testCandle(ctx: TBotContext<any>) { | ||
const { config: bot, onStart, onStop } = ctx; | ||
const exchange: IExchange = yield useExchange(); | ||
|
||
if (onStart) { | ||
logger.info( | ||
`[CandleStrategy] Bot started. Using ${exchange.exchangeCode} exchange`, | ||
); | ||
return; | ||
} | ||
if (onStop) { | ||
logger.info(`[CandleStrategy] Bot stopped`); | ||
return; | ||
} | ||
|
||
const market: MarketData = yield useMarket(); | ||
logger.info(market, `[CandleStrategy] Market data`); | ||
|
||
const candle: MarketData["candle"] = yield useCandle(); | ||
logger.info(`[CandleStrategy] Candle ${JSON.stringify(candle)}`); | ||
|
||
logger.info(`[CandleStrategy] Bot template executed successfully`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./buySell"; | ||
export * from "./trade"; | ||
export * from "./debug"; | ||
export * from "./candle"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters