解决nodejs循环依赖

时间:2019-06-24 10:52:24

标签: javascript node.js websocket binance

我知道这个问题已经问过几次了,但是我无法在我的项目结构中解决它。

我有3个文件:

  1. new_order.js
  2. binance.js
  3. advance.js

new_order.js负责初始化值,并将其传递给binance.js以执行订单。

然后

binance.js执行一个订单,并一直运行一个websocket来等待订单成交的事件。由于无法在websocket中返回值,因此我在下订单后立即致电advance.js

advance.js具有高级功能,例如止损/获利。我遇到的问题是,一旦价格达到止损/止盈水平,我必须再次致电binance.js来执行卖单。

我的流程是new_order.js-> binance.js <-> advance.js ..我该如何克服这个问题,也可以从binance.js返回一个值从全职运行的websocket返回new_order.js

1 个答案:

答案 0 :(得分:1)

创建一个文件index.js并按顺序将所有内容导入。然后在所有其余文件中从index.js导入。

// index.js
import * from "new_order"
import * from "binance.js"
import * from "advance.js"

// binance.js
import {func_from_advance} from "index.js"

// advance.js
import {func_from_binance} from "index.js"
相关问题